开发者

Cocoa-Touch: How to set the interpolation quality to be used by a UIImageView?

I have a UIImageView showing a image that is larger than it's frame.

It's se开发者_开发问答t to rescale the image to fit it's frame. But, the image is scaled with a low quality filter.

I've read here that this is caused by it using a low interpolation quality.

How can I get it's context to CGContextSetInterpolationQuality to kCGInterpolationHigh?


From "UIImageView scaling/interpolation", this is the most streamlined way to do it if you can:

[[yourimageview layer] setMagnificationFilter:kCAFilterTrilinear]

Be sure to #import <QuartzCore/CALayer.h>

A warning on kCAFilterTrilinear: "Some renderers may ignore this, or impose additional restrictions, such as source images requiring power-of-two dimensions."


UIImageView does not offer this functionality, though UIImage has an undocumented _imageScaledToSize:interpolationQuality: method if I remember correctly.

Since UIImageView draws directly to the display, subclassing and overriding drawRect: is no option (thanks to Prody for pointing this out). The only option I see is to create a custom UIView subclass with a custom drawrect: implementation.


CGContextSetInterpolationQuality is a function. You need to call it with whatever parameters are appropriate for your situation.

http://developer.apple.com/mac/library/qa/qa2001/qa1186.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜