裁剪图片后图像模糊?

3

我有一个应用程序,其中我正在裁剪从相机拍摄的图像。一切进行顺利。但是,在裁剪之后,图像看起来模糊和拉伸。

CGRect rect = CGRectMake(20,40,280,200);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

// translated rectangle for drawing sub image 
CGRect drawRect = CGRectMake(-rect.origin.x, -rect.origin.y,280,200);

// clip to the bounds of the image context
// not strictly necessary as it will get clipped anyway?
CGContextClipToRect(context, CGRectMake(0, 0, rect.size.width, rect.size.height));

// draw image
[image drawInRect:drawRect];

// grab image
UIImage* croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGSize size = [croppedImage size];
NSLog(@" = %@",NSStringFromCGSize(size));
NSData* pictureData = UIImagePNGRepresentation(croppedImage);

有人能帮我找出我做错了什么吗?

这段内容与IT技术无关,需要更多上下文才能确定正确的翻译。

你是指这篇文章吗 http://stackoverflow.com/questions/14645158/image-is-getting-stretched-and-blur-after-crop 还是这篇文章呢 http://stackoverflow.com/questions/12109519/uiimage-showing-blur-after-cropping-in-iphone ? - Joetjah
你可以提供一下截图吗? - Undo
请检查此链接:http://stackoverflow.com/questions/15288092/how-to-crop-the-captured-image-before-saving-it-in-gallery-in-ios/15288173#15288173 - Nitin Gohel
1个回答

2
尝试更换。
UIGraphicsBeginImageContext(rect.size);

使用

UIGraphicsBeginImageContextWithOptions(rect.size, NO, [[UIScreen mainScreen] scale]);

为了适应视网膜的要求。

但它给我一个双倍大小的图像,例如(560,400)的图像。 - hacker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接