9

我正在制作自己的 mp3 标记器,到目前为止一切都很好。虽然我坚持阅读专辑封面标签。

我想知道如何在 C#.NET 图片框中显示封面,但是关于该特定标签的所有内容都让我感到困惑。

我知道我可以从这样的文件中获取标签

txtAlbum.Text = currentFile.Tag.Album;

但我需要做的就是从文件中抓取图片并将其放入图片框中。然后我想知道如何将图片(jpg,png)写入文件并覆盖现有的。

任何帮助将不胜感激,并感谢您宝贵的时间。

4

2 回答 2

15

尝试这个

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);
        }
于 2012-04-20T14:01:33.563 回答
7

这是我针对该问题的快速而简短的解决方案:

var file = TagLib.File.Create(filename);
var bin = (byte[])(file.Tag.Pictures[0].Data.Data);
imageBox.Image = Image.FromStream(new MemoryStream(bin));
于 2014-09-02T15:14:47.607 回答