我正在使用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