0

我有这样的代码......

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;
}
4

1 回答 1

0

我不确定出了什么问题,但我相信可能是您的编写操作代码的速度不同。你能不使用这些函数来尝试原始写入操作吗?例如

for(int i = 0; i < bufferlen; i++) {
    pixelArray[i] = i; // or any arbitrary value
}
于 2010-09-30T02:22:04.563 回答