2012-07-24 147 views
0

我们有一个图像处理Windows应用程序,我们正在使用主要工具将24/48位图像转换为8位图像。将24位图像转换为8位单点触摸?

作为一个使用MonoTouch和C#将应用程序移植到iPad的实验,现在LeadTools组件与Monotouch不兼容。有什么替代我可以使用?如果不是我怎样才能将24/48位图像转换为8位?

+0

您对单色转换感兴趣吗? – user1071136 2012-07-24 15:12:13

回答

3

使用苹果的成像工具,这里是我将开始:

  1. 将您的原始字节到平台支持的像素格式。请参阅supported pixel formats上的Quartz 2D文档。
    请注意,iOS目前没有24位或48位格式。但是,如果您的24位格式是每通道8位(RGB),则可以添加8位忽略的alpha。 (Alpha选项在MonoTouch.CoreGraphics.CGImageAlphaInfo中)

  2. 将原始字节转换为CGImage。下面是如何做到这一点

    var provider = new CGDataProvider(bytes, 0, bytes.Length); 
        int bitsPerComponent = 8; 
        int components = 4; 
        int height = bytes.Length/components/width; 
        int bitsPerPixel = components * bitsPerComponent; 
        int bytesPerRow = components * width; // Tip: When you create a bitmap graphics context, you’ll get the best performance if you make sure the data and bytesPerRow are 16-byte aligned. 
        bool shouldInterpolate = false; 
        var colorSpace = CGColorSpace.CreateDeviceRGB(); 
        var cgImage = new CGImage(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, 
               colorSpace, CGImageAlphaInfo.Last, provider, 
               null, shouldInterpolate, CGColorRenderingIntent.Default); 
    
  3. 使用Core Image Filter转换为单色一个例子

    var mono = new CIColorMonochrome 
        { 
         Color = CIColor.FromRgb(1, 1, 1), 
         Intensity = 1.0f, 
         Image = CIImage.FromCGImage(image) 
        }; 
        CIImage output = mono.OutputImage; 
        var context = CIContext.FromOptions(null); 
        var renderedImage = context.CreateCGImage(output, output.Extent); 
    
  4. 最后,您可以通过绘制成CGBitmapContext根据构造检索图像的原始字节你想要的参数。

我怀疑这个管道可以优化,但它是一个开始的地方。我有兴趣听听你最终结果如何。

0

我认为你最好的选择是对LeadTools库进行本地调用 - 我能想到的C#中的任何图像操作都将依赖于像GDI +和System.Drawing命名空间这样的组件,它不受MonoTouch的。

您可以通过创建一个绑定项目从您的MonoTouch项目调用本地Objective-C代码 - http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types

这应该让你口你的代码将产生完全相同的图像/质量/格式没有办法真的不得不重新修改你当前的转换代码。