2010-09-29 39 views
0

后慢我有代码这样的事情...Buffere写变得CGBitmapContextCreate

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; 
} 
+0

向我们展示您的写入操作的代码部分? – tia 2010-09-29 17:14:42

+0

我用写代码更新了问题。 – Abix 2010-09-29 17:19:41

回答

0

我不知道是怎么回事错的,但我相信它可能是你写操作代码速度不同。你可以尝试原始写入操作而不使用这些函数吗?例如

for(int i = 0; i < bufferlen; i++) { 
    pixelArray[i] = i; // or any arbitrary value 
} 
+0

我已经尝试过,但这并没有帮助。如果我创建另一个缓冲区并执行一个memcpy(newBuffer,pixelArray)并在那里执行写入操作,事情会很好。好像有一次,我从内存块中创建一个图像后,会附上某种回调,不知道这是怎么回事。 – Abix 2010-09-30 02:35:13