Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#1

Memorystream vs TMemoryStream

  Alt 16. Apr 2015, 20: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