Loading Album art with TagLib sharp and then saving it to same/different file in C# causes memory error

后端 未结 3 764
余生分开走
余生分开走 2021-02-10 13:19

My application lists all MP3\'s in a directory and when the user selects a file it loads the tag info, including album art. The art is loaded into a variable to be used when the

3条回答
  •  没有蜡笔的小新
    2021-02-10 14:05

    your method isn't really false, only a few things had to be changed:

    // Method to save album art
    TagLib.Picture pic = new TagLib.Picture();
    pic.Type = TagLib.PictureType.FrontCover;
    pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg;
    pic.Description = "Cover";
    MemoryStream ms = new MemoryStream();
    currentImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); // <-- Error doesn't occur anymore
    ms.Position = 0;
    pic.Data = TagLib.ByteVector.FromStream(ms);
    f.Tag.Pictures = new TagLib.IPicture[1] { pic };
    f.save();
    ms.Close();
    

提交回复
热议问题