I have an application in which i am cropping the image taken from the camera.all are going well.but after the cropping the image seems to blured and streched.
我有一个应用程序,我正在裁剪从相机拍摄的图像。一切进展顺利。但在剪切之后,图像似乎变红,呈条纹状。
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);
Can anybody help me in finding out where i am going wrong?
有人能帮我找出我哪里出错了吗?
1 个解决方案
#1
2
try replacing
尝试更换
UIGraphicsBeginImageContext(rect.size);
with
与
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [[UIScreen mainScreen] scale]);
to account for retina
考虑到视网膜
#1
2
try replacing
尝试更换
UIGraphicsBeginImageContext(rect.size);
with
与
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [[UIScreen mainScreen] scale]);
to account for retina
考虑到视网膜