3

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?

Rince Thomas
  • 4,158
  • 5
  • 25
  • 44
hacker
  • 8,919
  • 12
  • 62
  • 108
  • Do you mean this http://stackoverflow.com/questions/14645158/image-is-getting-stretched-and-blur-after-crop or this http://stackoverflow.com/questions/12109519/uiimage-showing-blur-after-cropping-in-iphone ? – Joetjah Apr 09 '13 at 14:40
  • Could you provide a screenshot? – Undo Apr 09 '13 at 14:43
  • check this please:-http://stackoverflow.com/questions/15288092/how-to-crop-the-captured-image-before-saving-it-in-gallery-in-ios/15288173#15288173 – Nitin Gohel Apr 10 '13 at 06:42

1 Answers1

2

try replacing

UIGraphicsBeginImageContext(rect.size);

with

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

to account for retina

Or Arbel
  • 2,965
  • 2
  • 30
  • 40