我正在使用CGBitmapContextCreate
和CGContextDrawImage
将RGBA
数据绘制到屏幕上。当我尝试使用CGBitmapContextCreate
(pixelBuffer
,...)创建bitmapcontext
时,我已经有malloc
'ed pixelBuffer
并将我的数据放在那里,这很好。CGBitmapContextGetData - 无法将数据复制到返回的内存块中
不过,我想核芯显卡来管理它自己的内存,所以我想通过NULL
到CGBitmapContextCreate
,然后得到的指针调用CGBitmapContextGetData
,并使用复制我的RGBA
缓冲上述块所用的内存块memcpy
。但是,我的memcpy
失败。请参阅下面的代码。 任何想法我做错了什么?
gtx = CGBitmapContextCreate(NULL, screenWidth, screenHeight, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaNoneSkipLast);
void *data = CGBitmapContextGetData(gtx);
memcpy(data, pixelBuffer, area*componentsPerPixel);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGImageRef image = CGBitmapContextCreateImage(gtx);
CGContextTranslateCTM(currentContext, 0, screenHeight);
CGContextScaleCTM(currentContext, 1.0, -1.0);
CGContextDrawImage(currentContext, currentSubrect, image);
如果通过自己的指针工作,为什么不坚持呢? – nielsbot
我相信传递null是更优化的,我可能会得到一个绘图性能改进(这对我的应用程序很重要)。更重要的是,我偶然发现应用程序与vm_copy崩溃失败,我怀疑它可能与我传递自己的指针有关(只是一种直觉)。 –
好的,memcpy错误是什么? – nielsbot