我的CGBitmapcontext出了点问题。创建CGBitmapContext时出现错误,消息为"invalid Handle“。
下面是我的代码:
var previewContext = new CGBitmapContext(null, (int)ExportedImage.Size.Width, (int)ExportedImage.Size.Height, 8, (int)ExportedImage.Size.Height * 4, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst);谢谢你;
发布于 2012-04-12 14:57:25
这是因为您将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);发布于 2016-07-09 03:59:00
如果传入方法的width或height参数的值为0,也会发生这种情况。
https://stackoverflow.com/questions/10118388
复制相似问题