或者这个代码可以安全地在后台线程中执行?此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