Load image from photo library

核能气质少年 提交于 2019-11-30 08:54:38

问题


  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?

回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/3333652/load-image-from-photo-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!