簡體   English   中英

“無效的句柄”創建CGBitmapContext

[英]“Invalid Handle” Create CGBitmapContext

我的CGBitmapcontext有問題。 使用消息“無效的句柄”創建CGBitmapContext時出現錯誤。

這是我的代碼:

var previewContext = new CGBitmapContext(null, (int)ExportedImage.Size.Width, (int)ExportedImage.Size.Height, 8, (int)ExportedImage.Size.Height * 4,                                                    CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst);

謝謝;

那是因為您將null傳遞給第一個參數。 CGBitmapContext用於直接繪制到內存緩沖區中。 構造函數所有重載中的第一個參數是(Apple docs):

data指向內存中要繪制圖形的目標的指針。 該存儲塊的大小至少應為(bytesPerRow * height)個字節。

在MonoTouch中,為方便起見,我們得到了兩個接受byte []的重載。 因此,您應該像這樣使用它:

int bytesPerRow = (int)ExportedImage.Size.Width * 4; // note that bytes per row should 
    //be based on width, not height.
byte[] ctxBuffer = new byte[bytesPerRow * (int)ExportedImage.Size.Height];
var previewContext = 
    new CGBitmapContext(ctxBuffer, (int)ExportedImage.Size.Width, 
    (int)ExportedImage.Size.Height, 8, bytesPerRow, colorSpace, bitmapFlags);

如果傳遞給方法的widthheight參數的值為0,也會發生這種情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM