从照片库加载图像 [英] Load image from photo library

查看:130
本文介绍了从照片库加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 如何从照片库加载图像并在 imageView 中显示?

  2. 如何将图像更改为<强>黑白?

  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?


推荐答案

转换图像格式 UIImagePickerController 到黑白你可以使用这段代码:

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

这篇关于从照片库加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆