【发布时间】:2011-12-20 15:13:56
【问题描述】:
我正在尝试从颜色 PNG 和 alpha 中找到生成模糊灰度 UIImage 的配方。 ObjC 中有一些配方,但 MonoTouch 不绑定 CGRect 函数,因此不知道如何执行此操作。有什么想法吗?
这是一个 ObjC 灰度示例:
(UIImage *)convertImageToGrayScale:(UIImage *)image
{
// Create image rectangle with current image width/height
CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
// Grayscale color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
// Create bitmap content with current image size and grayscale colorspace
CGContextRef context = CGBitmapContextCreate(nil, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaNone);
// Draw image into current context, with specified rectangle
// using previously defined context (with grayscale colorspace)
CGContextDrawImage(context, imageRect, [image CGImage]);
// Create bitmap image info from pixel data in current context
CGImageRef imageRef = CGBitmapContextCreateImage(context);
// Create a new UIImage object
UIImage *newImage = [UIImage imageWithCGImage:imageRef];
// Release colorspace, context and bitmap information
CGColorSpaceRelease(colorSpace);
CGContextRelease(context);
CFRelease(imageRef);
// Return the new grayscale image
return newImage;
}
【问题讨论】:
-
我尝试使用此功能,但它不适用于 1.0 比例以外的图像...(视网膜断裂)
标签: ios xamarin.ios uiimage grayscale cgrect