旋转后的图像边框变得模糊ios

时间:2013-04-05 14:44:51

标签: iphone ios uiimageview cgcontext cgaffinetransform

在开发基于摄影的应用程序时,我需要旋转图像。但是在旋转图像后,它的边框变得模糊。我附上了这个屏幕截图..

enter image description here

正如您所看到的,第一张图片看起来不错,但其他旋转的图像效果不佳。

这是我的代码.....

        [img setBackgroundColor:[UIColor blackColor]];
        [img setContentMode:UIViewContentModeScaleAspectFit];
        [img.layer setBorderColor:[[UIColor whiteColor]CGColor]];
        [img.layer setBorderWidth:3.0];
        [img setTransform:CGAffineTransformMakeRotation(rotation*3.14/180)];

我使用过这个解决方案......

CGContextRotateCTM(context, radians);
[sourceImage drawInRect:rect];

但是当图像有边框时如何使用此代码。

请给出您宝贵的回应.....

2 个答案:

答案 0 :(得分:1)

旋转图像时,边框像素不会被抗锯齿:请参阅此question

解决方案虽然听起来很奇怪,但却是为图像提供1px透明边框。这个answer提供了为图片添加1px透明边框的代码。

答案 1 :(得分:0)

因为混叠效应。搜索“抗锯齿”。