开发者

Resolution loss with renderInContext: or CGImageCreateWithImageInRect?

开发者 https://www.devze.com 2023-02-15 12:06 出处:网络
I\'m taking a screen shot and cropping out the navigation bar/status bar.I don\'t think it works to crop within the context,so开发者_如何转开发 I\'m using the CGImage component to crop.The resulting i

I'm taking a screen shot and cropping out the navigation bar/status bar. I don't think it works to crop within the context,so开发者_如何转开发 I'm using the CGImage component to crop. The resulting image is a lot more pixelated than the original image I see on the screen. Does using the layer component disable quartz rendering? Am I losing the resolution during one of the conversions?

I am using a scrollView to allow zooming/panning, and am saving the image cropped by the screen size. The image is coming from UIImagePickerController. Is there a better way of doing this? I'm a newbie, suggestions are welcome.

    CGRect rect = CGRectMake(0, 44, 320, 436);
CGSize size = CGSizeMake(320, 480);

UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();

[self.view.layer renderInContext:context]; 
UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef ref = CGImageCreateWithImageInRect(tempImage.CGImage,rect);

finishedImage = [UIImage imageWithCGImage:ref];

[card saveImage:finishedImage];
UIGraphicsEndImageContext();

.....UPDATE.....

I've eliminated:

CGImageCreateWithImageInRect(problem is before it is called)

scrollview (didn't have an effect)

interpolation of context (is on already, tried different settings)

image from the imagePicker (low rez pic looks better direct from imagePicker than from renderInContext)

Most resolutions look fine. Its just when zoomed in and cropped, or low resolution pictures, that it looks worse than the original.

0

精彩评论

暂无评论...
验证码 换一张
取 消