MPMediaItemArtwork返回错误尺寸的图稿 [英] MPMediaItemArtwork returning wrong sized artwork

查看:354
本文介绍了MPMediaItemArtwork返回错误尺寸的图稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了与MPMediaItemArtwork一致的问题,因为它返回的图稿尺寸与我要求的尺寸不同。

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)];

这是按预期工作的,但返回图像的大小始终为 {320.0f,320.0f} 尽管我特意要求 {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?

苹果文档建议这应该像我期望的那样工作,而不是它实际上是如何

推荐答案

我下载了 AddMusic示例源也使用MPMediaItemArtwork来查看他们如何处理事情。

I downloaded the AddMusic sample source from Apple that also uses MPMediaItemArtwork just to see how they handled things.

在该项目的MainViewController.m文件中,这些行:

In that project's MainViewController.m file, these lines:

// 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)];
}

始终以1.0的比例返回大小为55 x 55的图像。

always returns an image of size 55 x 55 at a scale of 1.0.

我想说MPMediaItemArtwork不尊重请求的大小参数是你应该通过bugreporter.apple.com提交的错误,虽然苹果也可能有借口55 x 55英寸是在iPad和iPad上显示的最佳尺寸。 iPhone。

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.

对于钝器UIImage调整大小,我建议使用Trevor Harman的UIImage + Resize方法: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the -right-way

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:

UIImage *albumCover = [artwork imageWithSize:CGSizeMake(128.0f, 128.0f)];
UIImage *resizedCover = [albumCover resizedImage: CGSizeMake(128.0f, 128.0f) interpolationQuality: kCGInterpolationLow]; 

这篇关于MPMediaItemArtwork返回错误尺寸的图稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆