我遇到了一些问题,我在CALayer中绘制UIImage以显示它没有它的模糊性.我将400x300px图像放入123x89 CALayer中.这个尺度应该意味着得到的CALayer相对比较尖锐,但事实并非如此.
这是我用来绘制UIImage的代码:
CGSize s = image.size;
CGRect r = CGRectInset (bounds, 8, 8);
CGFloat scale = MIN (r.size.width / s.width, r.size.height / s.height);
s.width *= scale; s.height *= scale;
r.origin.x += (r.size.width - s.width) * .5;
r.size.width = s.width;
r.origin.y += (r.size.height - s.height) * .5;
r.size.height = s.height;
CGContextSaveGState (ctx);
CGContextTranslateCTM (ctx, 0, bounds.size.height);
CGContextScaleCTM (ctx, 1, -1);
if (image != nil) {
CGContextDrawImage (ctx, r, image.CGImage);
}
CGContextRestoreGState (ctx);
Run Code Online (Sandbox Code Playgroud)
如果您遇到同样的问题或知道这个问题的解决方案,任何帮助将不胜感激.
谢谢,
约书亚李塔克.