开发者

ImageQuality with CGContextSetInterpolationQuality

开发者 https://www.devze.com 2023-02-25 01:14 出处:网络
How effective is the CGContextSetInterpolationQuality method in Quartz? Doe开发者_运维技巧s it affect the quality of the image? If so, to what extent?

How effective is the CGContextSetInterpolationQuality method in Quartz?

Doe开发者_运维技巧s it affect the quality of the image? If so, to what extent?

I can't see any difference between the interpolated and the non-interpolated image.


Although this is a bit of an old question, I have recently done some benchmarking about the effects of CGContextSetInterpolationQuality and thought that its outcomes might be of interest to someone else.

In my benchmark test, I draw a set of 6 different 649x649 b&w bitmap images to build a set of 12 different jigsaw puzzle tiles. The bitmap images are scaled down by a factor of 5.0 (i.e., to 129.8x129.8) to make them fit on a 320x480 display (at retina display scale).

Run times on a 4th gen iPod touch, as reported by Instruments, are the following:

  • kCGInterpolationLow: 969 msec

  • kCGInterpolationMedium: 1690 msec

  • kCGInterpolationHigh: 2694 msec

  • kCGInterpolationNone: 545 msec

As to the visual outcome, if you compare High or Medium to Low or None, the difference is staggering. Even noticeable, IMO, the difference between None and Low; while the difference between High and Medium is not particularly noticeable in this particular test. What is clear is the difference in run times, so that in my particular case, I ended up using kCGInterpolationMedium.

kCGInterpolationNone

ImageQuality with CGContextSetInterpolationQuality

kCGInterpolationLow

ImageQuality with CGContextSetInterpolationQuality

kCGInterpolationMedium

ImageQuality with CGContextSetInterpolationQuality

kCGInterpolationHigh

ImageQuality with CGContextSetInterpolationQuality


The method

void CGContextSetInterpolationQuality ( CGContextRef c, CGInterpolationQuality quality );

affect the way Quartz renders an image into a CGContext. This e.g. comes into play when the source image is larger or smaller than the target bitmap CGContext.

To exactly answer your question of why you don't see any noticable difference, I will need more details about the exact usage, image sizes, context types, etc.

Exactly what interpolation methods the different quality levels cover seems undocumented. A guess from my side would however be:

  • Low: Nearest neighbor interpolation
  • Medium: Linear or bilinear interpolation
  • High: Quadratic or bicubic interpolation

Regards

0

精彩评论

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

关注公众号