[英]“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);
如果传递给方法的width
或height
参数的值为0,也会发生这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.