我們有一個圖像處理Windows應用程序,我們正在使用主要工具將24/48位圖像轉換爲8位圖像。將24位圖像轉換爲8位單點觸摸?
作爲一個使用MonoTouch和C#將應用程序移植到iPad的實驗,現在LeadTools組件與Monotouch不兼容。有什麼替代我可以使用?如果不是我怎樣才能將24/48位圖像轉換爲8位?
我們有一個圖像處理Windows應用程序,我們正在使用主要工具將24/48位圖像轉換爲8位圖像。將24位圖像轉換爲8位單點觸摸?
作爲一個使用MonoTouch和C#將應用程序移植到iPad的實驗,現在LeadTools組件與Monotouch不兼容。有什麼替代我可以使用?如果不是我怎樣才能將24/48位圖像轉換爲8位?
使用蘋果的成像工具,這裏是我將開始:
將您的原始字節到平臺支持的像素格式。請參閱supported pixel formats上的Quartz 2D文檔。
請注意,iOS目前沒有24位或48位格式。但是,如果您的24位格式是每通道8位(RGB),則可以添加8位忽略的alpha。 (Alpha選項在MonoTouch.CoreGraphics.CGImageAlphaInfo中)
將原始字節轉換爲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);
使用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);
最後,您可以通過繪製成CGBitmapContext根據構造檢索圖像的原始字節你想要的參數。
我懷疑這個管道可以優化,但它是一個開始的地方。我有興趣聽聽你最終結果如何。
我認爲你最好的選擇是對LeadTools庫進行本地調用 - 我能想到的C#中的任何圖像操作都將依賴於像GDI +和System.Drawing命名空間這樣的組件,它不受MonoTouch的。
您可以通過創建一個綁定項目從您的MonoTouch項目調用本地Objective-C代碼 - http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types
這應該讓你口你的代碼將產生完全相同的圖像/質量/格式沒有辦法真的不得不重新修改你當前的轉換代碼。
您對單色轉換感興趣嗎? – user1071136 2012-07-24 15:12:13