UIImage created from CGImageRef fails with UIImagePNGRepresentation
Posted
by Ari J.R.
on Stack Overflow
See other posts from Stack Overflow
or by Ari J.R.
Published on 2010-02-10T21:13:20Z
Indexed on
2010/05/01
4:07 UTC
Read the original article
Hit count: 579
I'm using the following code to crop and create a new UIImage out of a bigger one. I've isolated the issue to be with the function CGImageCreateWithImageInRect() which seem to not set some CGImage property the way I want. :-) The problem is that a call to function UIImagePNGRepresentation() fails returning a nil.
CGImageRef origRef = [stillView.image CGImage];
CGImageRef cgCrop = CGImageCreateWithImageInRect( origRef, theRect);
UIImage *imgCrop = [UIImage imageWithCGImage:cgCrop];
...
NSData *data = UIImagePNGRepresentation ( imgCrop);
-- libpng error: No IDATs written into file
Any idea what might wrong or alternative for cropping a rect out of UIImage? Many thanks!
© Stack Overflow or respective owner