//图片去色置灰处理
SDWebImageManager *manager = [SDWebImageManager sharedManager];
//保存图片URL
NSURL* url = [NSURL URLWithString:activityModel.activityImageUrl];
BOOL existBool = [manager diskImageExistsForURL:url];
if (existBool)
{
UIImage* image = [[manager imageCache]imageFromDiskCacheForKey:url.absoluteString];
self.image = [self grayImage:image];
}
else
{
[manager downloadImageWithURL:[NSURL URLWithString:activityModel.activityImageUrl]
options:0
progress:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (!error && image)
{
self.image = [self grayImage:image];
}
else
{
self.image = [self grayImage:[UIImage imageNamed:@"image_Activity_finishBG.png"]];
}
}];
}
图片置灰
-(UIImage *)grayImage:(UIImage *)sourceImage
{
int bitmapInfo = kCGImageAlphaNone;
int width = sourceImage.size.width;
int height = sourceImage.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef context = CGBitmapContextCreate (nil,
width,
height,
8, // bits per component
0,
colorSpace,
bitmapInfo);
CGColorSpaceRelease(colorSpace);
if (context == NULL) {
return nil;
}
CGContextDrawImage(context,
CGRectMake(0, 0, width, height), sourceImage.CGImage);
UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)];
CGContextRelease(context);
return grayImage;
}