我正在尝试对像素进行迭代,以在不使用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