问题
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.
回答1:
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);
}
回答2:
here's my quick and short solution for that problem:
var file = TagLib.File.Create(filename);
var bin = (byte[])(file.Tag.Pictures[0].Data.Data);
imageBox.Image = Image.FromStream(new MemoryStream(bin));
来源:https://stackoverflow.com/questions/10247216/c-sharp-mp3-id-tags-with-taglib-album-art