C# mp3 ID tags with taglib - album art

扶醉桌前 提交于 2019-12-18 01:03:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!