将位图设置为 MP3 的封面

Set Bitmap as cover art for MP3(将位图设置为 MP3 的封面)
本文介绍了将位图设置为 MP3 的封面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我一直在尝试将位图设置为 MP3 的封面,但我似乎无法让它工作.它没有抛出任何错误,但是当我播放 MP3 时,位图没有显示.

I have been trying to set a bitmap as cover art for a MP3 but I can't seem to get it working. It isn't throwing any errors but when I play the MP3 the bitmap isn't showing.

这是我目前拥有的:

TagLib.File f = TagLib.File.Create("song.mp3");

Image currentImage = getAlbumArt(result.passedAlbumID);
Picture pic = new Picture();
pic.Type = PictureType.FrontCover;
pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg;
pic.Description = "Cover";
MemoryStream ms = new MemoryStream();
currentImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
pic.Data = ByteVector.FromStream(ms);
f.Tag.Pictures = new IPicture[1] { pic };
pictureBox1.Image = currentImage; //testing the image is correct

f.Save();
ms.Close();

推荐答案

我正在使用以下代码,一切正常:

I'm using the following code and everything works fine for me:

TagLib.File file = TagLib.File.Create(/*path to your mp3 file*/);
TagLib.Picture pic = new TagLib.Picture();
pic.Type = TagLib.PictureType.FrontCover;
pic.Description = "Cover";
pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg;
MemoryStream ms = new MemoryStream();
/*your image*/.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
pic.Data = TagLib.ByteVector.FromStream(ms);
file.Tag.Pictures = new TagLib.IPicture[] { pic };
file.Save();
ms.Close();

根据您提供的代码,我唯一注意到的是,我的代码正在使用以下行

According to your provided code, the only thing I noticed is, that my code is using following line

file.Tag.Pictures = new TagLib.IPicture[] { pic };

代替

f.Tag.Pictures = new TagLib.IPicture[1] { pic };

所以简单地尝试一下,如果它在您删除方括号内的 1 时有效.

So simply try, if it works when you remove the 1 inside the square brackets.

这篇关于将位图设置为 MP3 的封面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

ActiveDirectory error 0x8000500c when traversing properties(遍历属性时 ActiveDirectory 错误 0x8000500c)
search by samaccountname with wildcards(使用通配符按 samaccountname 搜索)
Get the list of Groups for the given UserPrincipal(获取给定 UserPrincipal 的组列表)
Can you find an Active Directory User#39;s Primary Group in C#?(你能在 C# 中找到 Active Directory 用户的主要组吗?)
Query From LDAP for User Groups(从 LDAP 查询用户组)
How can I get DOMAINUSER from an AD DirectoryEntry?(如何从 AD DirectoryEntry 获取 DOMAINUSER?)