【问题标题】:Set Bitmap as cover art for MP3将位图设置为 MP3 的封面
【发布时间】:2015-05-17 08:50:39
【问题描述】:

我一直在尝试将位图设置为 MP3 的封面,但似乎无法正常工作。它没有抛出任何错误,但是当我播放 MP3 时,位图没有显示。

这是我目前拥有的:

TagLib.File f = TagLib.File.Create("song.mp3");

Image currentImage = getAlbumArt(result.passedAlbumID);
Picture pic = new Picture();
pic.Type = 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);
ms.Position = 0;
pic.Data = ByteVector.FromStream(ms);
f.Tag.Pictures = new IPicture[1] { pic };
pictureBox1.Image = currentImage; //testing the image is correct

f.Save();
ms.Close();

【问题讨论】:

    标签: c# bitmap taglib-sharp


    【解决方案1】:

    我正在使用以下代码,一切正常:

    TagLib.File file = TagLib.File.Create(/*path to your mp3 file*/);
    TagLib.Picture pic = new TagLib.Picture();
    pic.Type = TagLib.PictureType.FrontCover;
    pic.Description = "Cover";
    pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg;
    MemoryStream ms = new MemoryStream();
    /*your image*/.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    ms.Position = 0;
    pic.Data = TagLib.ByteVector.FromStream(ms);
    file.Tag.Pictures = new TagLib.IPicture[] { pic };
    file.Save();
    ms.Close();
    

    根据您提供的代码,我唯一注意到的是,我的代码正在使用以下行

    file.Tag.Pictures = new TagLib.IPicture[] { pic };
    

    而不是

    f.Tag.Pictures = new TagLib.IPicture[1] { pic };
    

    所以只要去掉方括号内的1就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 2020-05-06
      • 2015-05-10
      • 1970-01-01
      • 1970-01-01
      • 2011-10-22
      • 1970-01-01
      相关资源
      最近更新 更多