C# mp3 ID tags with taglib - album art

Purplebob picture Purplebob · Apr 20, 2012 · Viewed 13.6k times · Source

Im making my own mp3 tagger, and everything is fine so far. Although im stuck reading the album art tag.

I would like to know how to display the cover in a C#.NET picture box, but everything iv seen about that particular tag is confusing me.

I know i can get tags from files like this

txtAlbum.Text = currentFile.Tag.Album;

but all i need to do is grab the picture from the file and whack it in a picturebox. Then i would like to know how to write a picture (jpg, png) into the file and overwrite the existing one.

Any help would be greatly appreciated, and thank you for your valued time.

Answer

Likurg picture Likurg · Apr 20, 2012

Try this

TagLib.File tagFile = TagLib.File.Create(path);
IPicture newArt = new Picture(tmpImg);
tagFile.Tag.Pictures = new IPicture[1] {newArt};
tagFile.Save();

EDIT

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);
        }