AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Memorystream vs TMemoryStream

Ein Thema von EWeiss · begonnen am 16. Apr 2015 · letzter Beitrag vom 18. Apr 2015
 
EWeiss
(Gast)

n/a Beiträge
 
#1

Memorystream vs TMemoryStream

  Alt 16. Apr 2015, 21:44
Welche alternative gäbe es zu TMemoryStream?
Hab schon so vieles versucht aber alles führt nicht zu dem Ergebnis wie in Delphi.

Delphi
Delphi-Quellcode:
            PictureStream := TMemoryStream.Create;
            try
                PictureStream.LoadFromFile(OpenDialog1.FileName);
                PictureStream.Seek(0, soBeginning);
                Description := ExtractFileName(OpenDialog1.FileName);
                PictureStream.Read(PictureMagic, 2);
                PictureStream.Seek(0, soBeginning);
                if PictureMagic = MAGIC_JPG then begin
                    MIMEType := 'image/jpeg';
                    CoverArtPictureFormat := tpfJPEG;
                    JPEGPicture := TJPEGImage.Create;
                    try
                        JPEGPicture.LoadFromStream(PictureStream);
                        Width := JPEGPicture.Width;
                        Height := JPEGPicture.Height;
                        NoOfColors := 0;
                        ColorDepth := 24;
                    finally
                        FreeAndNil(JPEGPicture);
                    end;
                end;
Delphi-Quellcode:
                PictureStream.Seek(0, soBeginning);
                //* Add the cover art
                CoverArtData.Name := PwideChar(Description);
                CoverArtData.CoverType := 3; //* ID3v2 cover type (3: front cover)
                CoverArtData.MIMEType := PwideChar(MIMEType);
                CoverArtData.Description := PwideChar(Description);
                CoverArtData.Width := Width;
                CoverArtData.Height := Height;
                CoverArtData.ColorDepth := ColorDepth;
                CoverArtData.NoOfColors := NoOfColors;
                CoverArtData.PictureFormat := CoverArtPictureFormat;
                CoverArtData.Data := PictureStream.Memory;
                CoverArtData.DataSize := PictureStream.Size;
                if TagsLibrary_AddCoverArt(Tags, ttAutomatic, CoverArtData) = - 1 then begin
                    MessageDlg('Error while adding cover art: ' + SaveDialog1.FileName, mtError, [mbCancel], 0);
C#
Code:
    private void btnAdd_MouseDown(object sender, MouseEventArgs e)
    {
      //* Clear the cover art data
      string MIMEType = "";
      string Description = "";
      int Width = 0;
      int Height = 0;
      int ColorDepth = 0;
      int NoOfColors = 0;
      TCoverArtData CoverArtData = new TCoverArtData();

      TTagPictureFormat CoverArtPictureFormat = TTagPictureFormat.tpfUnknown;

      OpenFileDialog1.FileName = "";
      OpenFileDialog1.Title = "Select a File...";
      OpenFileDialog1.Filter = "Picture files (*.jpg*,*.jpeg*,*.bmp*,*.png*,*.gif*)|*.jpg*;*.jpeg*;*.bmp*;*.png*;*.gif*";

      if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
      {
        if (File.Exists(OpenFileDialog1.FileName))
        {
          using (Stream BitmapStream = System.IO.File.Open(OpenFileDialog1.FileName, System.IO.FileMode.Open))
          {
            Image img = Image.FromStream(BitmapStream);

            if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
            {
              MIMEType = "image/jpeg";
              CoverArtPictureFormat = TTagPictureFormat.tpfJPEG;
              Description = Path.GetFileName(OpenFileDialog1.FileName);
              Width = img.Width;
              Height = img.Height;
              NoOfColors = 0;
              ColorDepth = 24;
            }
            else if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png))
            {
              //TODO
            }
            else if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif))
            {
              //TODO
            }
            else if (img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Bmp))
            {
              //TODO
            }

            CoverArtData.Name = Description;
            CoverArtData.CoverType = 3;
            CoverArtData.MIMEType = MIMEType;
            CoverArtData.Description = Description;
            CoverArtData.Width = Width;
            CoverArtData.Height = Height;
            CoverArtData.ColorDepth = ColorDepth;
            CoverArtData.NoOfColors = NoOfColors;
            CoverArtData.PictureFormat = CoverArtPictureFormat;
            //CoverArtData.Data = ?;
            CoverArtData.DataSize = BitmapStream.Length;
            if (TagsLib.TagsLibrary_AddCoverArt(Tags, TTagType.ttAutomatic, CoverArtData) != 0)
            {
              MessageBox.Show("Error while adding cover art: ", OpenFileDialog1.FileName, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
            }
          }
        }
      }
    }
Ich weis nicht wie ich den Part hier übergeben soll.
Zitat:
//CoverArtData.Data = ?;
Den Delphi teil kann ich nicht exakt übersetzen da es mit keinem Stream funktioniert.

gruss
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz