Problem in cropping the UIImage using CGContext?

Posted by Rajendra Bhole on Stack Overflow See other posts from Stack Overflow or by Rajendra Bhole
Published on 2010-04-16T18:05:01Z Indexed on 2010/04/16 18:53 UTC
Read the original article Hit count: 483

Filed under:
|
|

Hi, I developing the simple UIApplication in which i want to crop the UIImage (in .jpg format) with help of CGContext. The developed code till now as follows,

CGImageRef graphicOriginalImage = [originalImage.image CGImage];

UIGraphicsBeginImageContext(originalImage.image.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGBitmapContextCreateImage(graphicOriginalImage);

CGFloat fltW = originalImage.image.size.width;
CGFloat fltH = originalImage.image.size.height;
CGFloat X = round(fltW/4); 
CGFloat Y =round(fltH/4);
CGFloat width = round(X + (fltW/2));
CGFloat height = round(Y + (fltH/2));   

CGContextTranslateCTM(ctx, 0, image.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGRect rect = CGRectMake(X,Y ,width ,height); 
CGContextDrawImage(ctx, rect, graphicOriginalImage);

croppedImage = UIGraphicsGetImageFromCurrentImageContext();

return croppedImage;

} The above code is worked fine but it can't crop image. The original image memory and cropped image memory i will got same(equal to original image memory). The above code is right for cropping the image?????????????????? How i cropping the image (in behind pixels should also be crop) from the center of the image???????????? I already wasting a lot of time for developing the above code , but i didn't get answer or way to find out how to crop the image.Thanks for sending me answer in advanced.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about image