但是当我使用drawInRect API在上下文中绘制图片时,图片就像这样
rect的大小就是图像的大小。图像是@ 1x和@ 2x。
差异非常明显,图像模糊,图像右侧有灰线,而我的imac是视网膜分辨率。
=============================================== = 我找到了原因,
[self.headLeftImage drawInRect:NSMakeRect(100,
100,
self.headLeftImage.size.width,
self.headLeftImage.size.height)];
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
CGContextSaveGState(context);
CGContextTranslateCTM(context, self.center.x , self.center.y);
[self.headLeftImage drawInRect:NSMakeRect(100,
100,
self.headLeftImage.size.width,
self.headLeftImage.size.height)];
CGContextRestoreGState(context);
答案 0 :(得分:1)
问题在于您将上下文转换为非整数像素位置。然后,绘图是为了表示您将图像置于非整数位置的请求,这会使其在某些像素中部分消除锯齿和颜色。
您应该将中心点转换为设备空间,对其进行积分(例如,使用floor()
),然后将其转换回来。使用CGContextConvertPointToDeviceSpace()
和CGContextConvertPointToUserSpace()
进行转化。这对Retina和非Retina显示器来说是正确的。