DrawInRect: потеря качества изображения - программирование
Подтвердить что ты не робот

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();

Но я просто узнал, что Image потерял разрешение из-за drawInRect.

BeforeAfter

4b9b3361

Ответ 1

Вы должны пойти с UIGraphicsBeginImageContextWithOptions вместо UIGraphicsBeginImageContext, чтобы указать масштабный коэффициент.

Например, это будет использовать масштабный коэффициент главного экрана устройства:

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