我有这样的代码......
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(pixelArray, width, height, 8, 4 * width, colorSpace, kCGImageAlphaNoneSkipLast);
CGImageRef createdImage = CGBitmapContextCreateImage (ctx);
uiImage = [[UIImage imageWithCGImage:createdImage] retain];
问题是,一旦我从缓冲区(pixelArray)创建了 CGImage 和 UIImage,任何写入缓冲区的操作都会至少慢 4 倍。这只发生在 iPad 设备上而不是 iPhone 上。有没有人面临同样的问题?这里发生了什么?
这是写操作代码,我在循环中调用它们(setPixel)......
- (RGBA*) getPixel:(NSInteger)x y:(NSInteger)y {
// Bound the co-cordinates.
x = MIN(MAX(x, 0), width - 1);
y = MIN(MAX(y, 0), height - 1);
// yIndexes are pre populated
return (RGBA*)(&pixelArray[(x + yIndexes[y]) << 2]);
}
- (void) setPixel:(RGBA*)color x:(NSInteger)x y:(NSInteger)y {
// Bound the co-cordinates.
x = MIN(MAX(x, 0), _width);
y = MIN(MAX(y, 0), _height);
memcpy([self getPixel:x y:y], color, 3);
colorDirtyBit = YES;
}