gpt4 book ai didi

c# - 将位图设置为 MP3 的封面

转载 作者:太空宇宙 更新时间:2023-11-03 18:27:41 24 4
gpt4 key购买 nike

我一直在尝试将位图设置为 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();

最佳答案

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

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 时有效。

关于c# - 将位图设置为 MP3 的封面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30285069/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com