2013-02-06 152 views
16

的失去质量,我尝试使用擦除图像下面的代码drawInRect:图像分辨率

CGColorRef strokeColor = [UIColor whiteColor].CGColor; 

UIGraphicsBeginImageContext(imgForeground.frame.size); 

CGContextRef context = UIGraphicsGetCurrentContext(); 
[imgForeground.image drawInRect:CGRectMake(0, 0, imgForeground.frame.size.width, imgForeground.frame.size.height)]; 

CGContextSetLineCap(context, kCGLineCapRound); 
CGContextSetLineWidth(context, 10); 

CGContextSetStrokeColorWithColor(context, strokeColor); 
CGContextSetBlendMode(context, kCGBlendModeClear); 

CGContextBeginPath(context); 
CGContextMoveToPoint(context, lastPoint.x, lastPoint.y); 
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y); 
CGContextStrokePath(context); 

imgForeground.image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

但我只是看看图片失去其分辨率因drawInRect

BeforeAfter

+0

上传“之前”和“之后”屏幕显示图像会有很大的帮助,包括视觉效果的问题。 – dasblinkenlight

+0

上传图片请参照 –

+0

目前尚不清楚“图像分辨率质量下降”的含义。也许你可以尝试更具体些。 – ipmcc

回答

38

您应该UIGraphicsBeginImageContextWithOptions而不是UIGraphicsBeginImageContext走,这样可以指定一个比例系数。

例如,这将使用设备的主屏幕的比例因子:

UIGraphicsBeginImageContextWithOptions(imgForeground.frame.size, NO, 0); 
+0

如果图像不是Window的大小怎么办? 比用什么来替换imgForeground.window.screen.scale –

+0

嗨!那么,第三个参数是比例尺,而不是任何尺寸(即尺寸)!对于没有Retina显示器的所有iPhone,iPodTouch等,它将返回1.0f,而Retina显示设备将提供2.0f。 –

+1

用'[[UIScreen mainScreen] scale]'替换'imgForeground.window.screen.scale'',所以更清楚的是“屏幕”的缩放意味着什么! –