18

次のコードを使用して画像を消去しようとしています

 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が原因でImageが解像度を失っていることがわかりました。

前 後

4

1 に答える 1

45

倍率を指定できるように、UIGraphicsBeginImageContextWithOptionsの代わりにを使用する必要があります。UIGraphicsBeginImageContext

たとえば、これはデバイスのメイン画面の倍率を使用します。

UIGraphicsBeginImageContextWithOptions(imgForeground.frame.size, NO, 0);
于 2013-02-06T12:41:29.230 に答える