Tôi đang cố gắng tìm một công thức để tạo ra một màu xám mờ UIImage
từ một màu PNG và alpha. Có những công thức có trong ObjC nhưng MonoTouch không ràng buộc các hàm CGRect
vì vậy không chắc chắn làm thế nào để làm điều này. Ý tưởng nào?MonoTouch chuyển đổi màu UIImage thành alpha sang thang độ xám và mờ?
Dưới đây là một ví dụ về ObjC màu xám:
(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;
}
Tôi đã cố gắng để sử dụng chức năng này nhưng nó sẽ không làm việc với hình ảnh khác hơn 1.0 quy mô ... (ngắt trên võng mạc) – Jonny