问题描述
我想在Windows窗体图片框中显示歌曲的专辑插图(可通过taglib-sharp库访问)。我遇到的问题是,taglib库返回的图像类型为 TagLib.IPicture
,而图片框需要的对象类型为 System .Drawing.Image
。
I am wanting to display the album artwork of a song (accessed via the taglib-sharp library) within a Windows Forms picture box. The problem I'm running into is that the taglib-library returns an image of type TagLib.IPicture
whereas the picture box requires an object of type System.Drawing.Image
.
我已经在互联网上搜寻了很多小时,正在寻找一种方法来从 IPicture 到图片
,但无济于事。我最好的线索是:,但是我还没有看到如何实现此效果的成功示例。
I have scoured the internet for many hours now, looking for a way to convert from an IPicture
to Image
, but to no avail. The best lead I have is this: http://msdn.microsoft.com/en-us/library/system.windows.forms.axhost.getpicturefromipicture.aspx, but I have yet to see a successful example of how to implement this.
关于如何在这两种类型之间进行转换的任何帮助将不胜感激。 注意: IPicture
在这种情况下与 IPictureDisp
类似。
Any help as to how to convert between these two types would be much appreciated. Note: IPicture
is not analogous to IPictureDisp
in this case.
推荐答案
我之前做过相反的工作-将现有的.jpg转换为IPicture,以嵌入到.mp3文件中。我只是尝试反转该操作,并且在进行了调整和测试之后,提出了以下建议:
I've done the opposite before - turning an existing .jpg into an IPicture for embedding in an .mp3 file. I just tried reversing that operation and, after tweaking and testing, came up with this:
TagLib.File tagFile = TagLib.File.Create(mp3FilePath);
MemoryStream ms = new MemoryStream(tagFile.Tag.Pictures[0].Data.Data);
System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
感谢您提出问题-我已经知道自己将如何使用它!
Thanks for the question - I already know how I'm going to use this myself!
更新:这是另一种方式(.jpg到我之前做过的IPicture):
Update: Here's the other way (.jpg to IPicture that I've done before):
tagFile.Tag.Pictures = new TagLib.IPicture[]
{
new TagLib.Picture(new TagLib.ByteVector((byte[])new System.Drawing.ImageConverter().ConvertTo(System.Drawing.Image.FromFile(jpgFilePath), typeof(byte[]))))
};
这篇关于如何将IPicture转换为图像-.NET 4.5 TagLib Sharp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!