我正在嘗試對像素進行迭代,以在不使用OpenGL的情況下更改UIImage的RGBA值。我嘗試使用下面的代碼測試迭代性能,但非常不滿。似乎我每秒只能獲得幾千次迭代。而對於數十萬像素的UIImage來說,這將取代TOO LONG ...任何人對於如何提高性能或這些操作通常需要多長時間都有任何建議?Core Graphics在iPhone上的PIXEL迭代性能很差嗎?
-(UIImage*)modifyPixels:(UIImage*)originalImage
{
NSData* pixelData = (NSData*)CGDataProviderCopyData(CGImageGetDataProvider(originalImage.CGImage));
void* pixelBytes = [pixelData bytes];
// Take away the red pixel, assuming 32-bit RGBA
for(int i = 0; i < [pixelData length]; i += 4) {
NSLog(@" %ith iteration (%i/%i/%i/%i)", i, pixelData[i], pixelData[i+1], pixelData[i+2], pixelData[i+3]);
}
//NSData* newPixelData = [NSData dataWithBytes:pixelBytes length:[pixelData length]];
//UIImage* newImage = [UIImage imageWithData:newPixelData];
return originalImage;
}
請注意,您在此處泄漏pixelData。包含「複製」的核心基礎(和通過擴展的CG)函數會返回一個保留對象。 – 2009-08-30 02:55:33
好的,謝謝你。 – RexOnRoids 2009-08-30 03:17:42