2

CGBitmapcontextに問題があります。「invalidHandle」というメッセージが表示されたCGBitmapContextの作成中にエラーが発生します。

これが私のコードです:

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

ありがとうございました;

4

2 に答える 2

6

これは、最初のパラメーターに null を渡しているためです。CGBitmapContext は、メモリ バッファに直接描画するためのものです。コンストラクターのすべてのオーバーロードの最初のパラメーターは (Apple ドキュメント) です。

data 描画がレンダリングされるメモリ内の宛先へのポインタ。このメモリ ブロックのサイズは、少なくとも (bytesPerRow*height) バイトである必要があります。

MonoTouch では、便宜上 byte[] を受け入れる 2 つのオーバーロードを取得します。したがって、次のように使用する必要があります。

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);
于 2012-04-12T06:57:24.807 に答える
0

これは、メソッドに渡されたwidthまたはパラメータの値が 0 の場合にも発生する可能性があります。height

于 2016-07-08T19:59:00.040 に答える