iPhone 彩色图片转变为黑白图片

CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
	
// 创建gray的CGColorSpaceRef
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
	
// 创建CGContextRef
CGContextRef context = CGBitmapContextCreate(nil, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaNone);
	
CGContextDrawImage(context, imageRect, [image CGImage]);
	
CGImageRef imageRef = CGBitmapContextCreateImage(context);

UIImage *newImage = [UIImage imageWithCGImage:imageRef];
	
CGColorSpaceRelease(colorSpace);
CGContextRelease(context);
CFRelease(imageRef);

你可能感兴趣的:(java)