MPMediaItemArtwork 返回错误尺寸的图稿
我发现 MPMediaItemArtwork 存在一个一致的问题,即它返回的图稿尺寸与我请求的尺寸不同。
我使用的代码如下
MPMediaItem *representativeItem = [self.representativeItems objectAtIndex:index];
MPMediaItemArtwork *artwork = [representativeItem valueForProperty:MPMediaItemPropertyArtwork];
UIImage *albumCover = [artwork imageWithSize:CGSizeMake(128.0f, 128.0f)];
这按预期工作,除了返回图像的大小始终为 {320.0f, 320.0f}
即使我特别要求 {128.0f , 128.0f}
并且由于图像大小是预期大小的两倍以上,它导致了一些内存问题。
还有其他人目睹过这个特定问题吗?你是怎么解决的?
苹果文档表明这应该按照我的预期工作,而不是实际情况
I'm seeing a consistent issue with MPMediaItemArtwork in that it's returning artwork in a size different to that which I request.
The code I'm using is as follows
MPMediaItem *representativeItem = [self.representativeItems objectAtIndex:index];
MPMediaItemArtwork *artwork = [representativeItem valueForProperty:MPMediaItemPropertyArtwork];
UIImage *albumCover = [artwork imageWithSize:CGSizeMake(128.0f, 128.0f)];
This works as expected, except that the size of the returned image is always {320.0f, 320.0f}
even though I specifically asked for {128.0f, 128.0f}
and it's causing some memory issues due to the images being more than twice the size of those expected.
Has anyone else witnessed this particular issue. How did you resolve it?
Apples docs suggest this should work as I'm expecting it to rather than how it actually is
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从 Apple 下载了 AddMusic 示例源,它也使用 MPMediaItemArtwork 只是为了看看他们如何处理事情。
在该项目的 MainViewController.m 文件中,这些行:
始终返回尺寸为 55 x 55、比例为 1.0 的图像。
我想说 MPMediaItemArtwork 不尊重所请求的尺寸参数是一个错误,您应该通过 bugreporter.apple.com 提交,尽管 Apple 也可能有借口说“55 x 55”是在 iPad 和 iPad 上显示的最佳尺寸。 iPhone。
对于钝力 UIImage 调整大小,我建议使用 Trevor Harman 的“UIImage+Resize”方法:http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way
一旦你将他的类别扩展添加到您的项目中,您可以通过像这样的简单调用来完成您想要的节省内存的调整大小:
I downloaded the AddMusic sample source from Apple that also uses MPMediaItemArtwork just to see how they handled things.
In that project's MainViewController.m file, these lines:
always returns an image of size 55 x 55 at a scale of 1.0.
I would say MPMediaItemArtwork not respecting the requested size parameters is a bug that you should file via bugreporter.apple.com, although Apple might also have an excuse that "55 x 55" is some optimal size to be displayed on iPads & iPhones.
For blunt force UIImage resizing, I'd recommend using Trevor Harman's "UIImage+Resize" methods found here: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way
And once you add his category extensions to your project, you could do your desired memory-conserving resizing with a simple call like this:
使用 Trevor Harman 的“UIImage+Resize”类别,可以简单地将调整大小类别添加到 MPMediaItemArtwork 以获得特定大小和插值质量的调整大小图像:
这样只需调用
Using the Trevor Harman's "UIImage+Resize" category it's simple to add resize category to the MPMediaItemArtwork to get the resized image for a certain size and interpolation quality:
In this way just call