问题描述
我想在 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
转换为 Image
的方法,但无济于事.我拥有的最好的线索是:http://msdn.microsoft.com/en-us/library/system.windows.forms.axhost.getpicturefromipicture.aspx,但我还没有看到如何实现这一点的成功示例.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!