我下载了AddMusic 示例源 http://developer.apple.com/library/ios/#samplecode/AddMusic/Introduction/Intro.htmlApple 也使用 MPMediaItemArtwork 只是为了看看他们如何处理事情。
在该项目的 MainViewController.m 文件中,这些行:
// Get the artwork from the current media item, if it has artwork.
MPMediaItemArtwork *artwork = [currentItem valueForProperty: MPMediaItemPropertyArtwork];
// Obtain a UIImage object from the MPMediaItemArtwork object
if (artwork) {
artworkImage = [artwork imageWithSize: CGSizeMake (30, 30)];
}
始终返回尺寸为 55 x 55、比例为 1.0 的图像。
我想说 MPMediaItemArtwork 不尊重所请求的尺寸参数是一个错误,您应该通过 bugreporter.apple.com 提交,尽管 Apple 也可能有借口说“55 x 55”是在 iPad 和 iPhone 上显示的最佳尺寸。
对于直接调整 UIImage 大小,我建议使用 Trevor Harman 的“UIImage+Resize”方法:http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way
一旦你将他的类别扩展添加到你的项目中,你就可以通过像这样的简单调用来完成你想要的节省内存的调整大小:
UIImage *albumCover = [artwork imageWithSize:CGSizeMake(128.0f, 128.0f)];
UIImage *resizedCover = [albumCover resizedImage: CGSizeMake(128.0f, 128.0f) interpolationQuality: kCGInterpolationLow];