4

I have a UIImageView showing a image that is larger than it's frame.
It's set 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?

Prody
  • 5,182
  • 6
  • 44
  • 62

3 Answers3

2

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."

Community
  • 1
  • 1
Kaolin Fire
  • 2,521
  • 28
  • 43
1

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

Azeem.Butt
  • 5,855
  • 1
  • 26
  • 22
1

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.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • From the docs: The UIImageView class is optimized to draw its images to the display. UIImageView will not call drawRect:. I can't find any mention of _imageScaledToSize:interpolationQuality. I guess for now I'll draw my image in the parent view's drawRect. – Prody Nov 01 '09 at 18:21
  • Thanks for the correction, Prody. I should have read the docs before posting. I will edit my answer accordingly. – Ole Begemann Nov 01 '09 at 18:47