SajjadZare
SajjadZare

Reputation: 2378

Load image from photo library

  1. How can I load an image from photo library and show it in imageView?
  2. How can I change image to black and white?

Upvotes: 0

Views: 3527

Answers (2)

jamapag
jamapag

Reputation: 9318

To convert image form UIImagePickerController to black and white you can use this code:

UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage]; // this image we get from UIImagePickerController

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);

Upvotes: 1

Pugalmuni
Pugalmuni

Reputation: 9390

If you want to load an image from photo library, you have to use UIImagePickerController class. Refer this Link

Upvotes: 3

Related Questions