Sha*_*tha 17 cocoa-touch quartz-graphics uiimage cgcontext ios
我试图使用以下代码擦除图像
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();
Run Code Online (Sandbox Code Playgroud)
但我发现由于drawInRect,Image会失去分辨率.
Nen*_*d M 42
您应该使用UIGraphicsBeginImageContextWithOptions
而不是UIGraphicsBeginImageContext
,以便可以指定比例因子.
例如,这将使用设备主屏幕的比例因子:
UIGraphicsBeginImageContextWithOptions(imgForeground.frame.size, NO, 0);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4531 次 |
最近记录: |