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.
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
精彩评论