或者這個代碼可以安全地在後臺線程中執行?此UIImage數據讀取器線程安全嗎?
CGImageRef cgImage;
CGContextRef context;
CGColorSpaceRef colorSpace;
// Sets the CoreGraphic Image to work on it.
cgImage = [uiImage CGImage];
// Sets the image's size.
_width = CGImageGetWidth(cgImage);
_height = CGImageGetHeight(cgImage);
// Extracts the pixel informations and place it into the data.
colorSpace = CGColorSpaceCreateDeviceRGB();
_data = malloc(_width * _height * 4);
context = CGBitmapContextCreate(_data, _width, _height, 8, 4 * _width, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
// Adjusts position and invert the image.
// The OpenGL uses the image data upside-down compared commom image files.
CGContextTranslateCTM(context, 0, _height);
CGContextScaleCTM(context, 1.0, -1.0);
// Clears and ReDraw the image into the context.
CGContextClearRect(context, CGRectMake(0, 0, _width, _height));
CGContextDrawImage(context, CGRectMake(0, 0, _width, _height), cgImage);
// Releases the context.
CGContextRelease(context);
如果獲得相同的結果,如果沒有?
(我的問題是,我不能看到我的OpenGL紋理基於該方法的輸出緩衝,如果它在後臺運行)
我喜歡這個答案,但我完全無法理解它。 – Geri 2012-08-07 11:15:19
這是否像「保留」緩衝區一段時間?每次我想將圖像推送到紋理時,我都會創建一個UIImageDataParser實例,所以緩衝區不應該「混淆」。也許我只是簡單地釋放緩衝區? – Geri 2012-08-07 11:17:16
我試圖在後臺線程上釋放數據對象,但沒有結果。 – Geri 2012-08-07 11:22:51