Converting image to Black & White image on iPhone SDK issues.

Posted by KfirS on Stack Overflow See other posts from Stack Overflow or by KfirS
Published on 2011-01-15T10:21:06Z Indexed on 2011/01/15 11:53 UTC
Read the original article Hit count: 206

Filed under:
|
|
|

Hello,

I've used a familiar code to convert image to Black & White which I've founded on several forums.
The code is:

CGColorSpaceRef colorSapce = CGColorSpaceCreateDeviceGray();
CGContextRef context = CGBitmapContextCreate(nil, originalImage.size.width,     originalImage.size.height, 8, originalImage.size.width, colorSapce, kCGImageAlphaNone);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetShouldAntialias(context, NO);
CGContextDrawImage(context, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), [originalImage CGImage]);
CGImageRef bwImage = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSapce);

UIImage *resultImage = [UIImage imageWithCGImage:bwImage]; // This is result B/W image.
CGImageRelease(bwImage);

return resultImage;

When I'm using this code with on Horizontal image it's work fine,
but when I'm trying a to use this code on Vertical image, the result is disproportionate image and rotate 90 degree left.

Can anyone know what could be the problem?

Thanks, Kfir.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode