2012-10-01 100 views
0

我正在使用CGBitmapContextCreateCGContextDrawImageRGBA数据绘制到屏幕上。当我尝试使用CGBitmapContextCreatepixelBuffer,...)创建bitmapcontext时,我已经有malloc'ed pixelBuffer并将我的数据放在那里,这很好。CGBitmapContextGetData - 无法将数据复制到返回的内存块中

不过,我想核芯显卡来管理它自己的内存,所以我想通过NULLCGBitmapContextCreate,然后得到的指针调用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); 
+0

如果通过自己的指针工作,为什么不坚持呢? – nielsbot

+0

我相信传递null是更优化的,我可能会得到一个绘图性能改进(这对我的应用程序很重要)。更重要的是,我偶然发现应用程序与vm_copy崩溃失败,我怀疑它可能与我传递自己的指针有关(只是一种直觉)。 –

+0

好的,memcpy错误是什么? – nielsbot

回答

0

根据我的所有研究,使用drawRect中绘制频繁/反复是一个坏主意,所以我决定转移到基于UIImageView的绘制,如在此之外的响应建议SO question

这里的另一个所以回答为什么UIImageView比drawrect更高效。

基于上述情况,我现在使用UIImageView代替drawrect,并且看到更好的绘图性能。

相关问题