She*_*age 9 uiimage grayscale xamarin.ios ios cgrect
我试图找到一个UIImage从PNG和alpha颜色生成模糊灰度的配方.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;
}
pou*_*pou 13
Monotouch不绑定
CGRect功能,因此不确定如何执行此操作.
使用MonoTouch时CGRect映射到RectangleF.存在许多应该映射到每个函数的扩展方法GCRect.使用它们移植ObjectiveC代码应该没有任何问题.
如果缺少某些内容,请填写错误报告@ http://bugzilla.xamarin.com,我们将尽快修复它(并在可能的情况下提供解决方法).
ObjC中有配方,但有MonoTouch
如果您有链接,请编辑您的问题并添加它们.这将使你更容易帮助你:)
UPDATE
这是您的示例的逐行C#转换.它似乎对我有用(而且我的眼睛比Objective-C更容易;-)
    UIImage ConvertToGrayScale (UIImage image)
    {
        RectangleF imageRect = new RectangleF (PointF.Empty, image.Size);
        using (var colorSpace = CGColorSpace.CreateDeviceGray ())
        using (var context = new CGBitmapContext (IntPtr.Zero, (int) imageRect.Width, (int) imageRect.Height, 8, 0, colorSpace, CGImageAlphaInfo.None)) {
            context.DrawImage (imageRect, image.CGImage);
            using (var imageRef = context.ToImage ())
                return new UIImage (imageRef);
        }
    }
| 归档时间: | 
 | 
| 查看次数: | 5563 次 | 
| 最近记录: |