我正在制作自己的MP3标签编辑器,目前一切正常。不过,我卡在了读取专辑封面标签的地方。
我想知道如何在C#.NET的图片框中显示封面,但是我看到的所有关于这个特定标签的内容都让我感到困惑。
我知道可以像这样从文件中获取标签:
txtAlbum.Text = currentFile.Tag.Album;
但我只需要从文件中提取图片并将其放入一个picturebox。然后,我想知道如何将图片(jpg、png)写入文件并覆盖现有的文件。
非常感谢您的帮助,并感谢您宝贵的时间。
试一试
TagLib.File tagFile = TagLib.File.Create(path);
IPicture newArt = new Picture(tmpImg);
tagFile.Tag.Pictures = new IPicture[1] {newArt};
tagFile.Save();
编辑
var file = TagLib.File.Create(filename);
if (file.Tag.Pictures.Length >= 1)
{
var bin = (byte[])(file.Tag.Pictures[0].Data.Data);
PreviewPictureBox.Image = Image.FromStream(new MemoryStream(bin)).GetThumbnailImage(100, 100, null, IntPtr.Zero);
}
var file = TagLib.File.Create(filename);
var bin = (byte[])(file.Tag.Pictures[0].Data.Data);
imageBox.Image = Image.FromStream(new MemoryStream(bin));