我正在努力寻找在iPad 3上用iOS绘制图像的最优化方法。我正在为我的应用程序中实现的coverflow的第三方版本生成一个反射。反射是使用NSOperationQueue创建的,然后在主线程中通过UIImageView添加。因为当你滚动图片时,coverflow部分已经在为动画使用资源,每添加一个新图片,滚动中就会有一些“弹出”,这会让应用程序感觉有点滞后/不顺畅。在iPad 1和2上测试,动画非常流畅,看起来很棒。
如何进一步优化绘图以避免这种情况。任何想法都是值得感谢的。我一直在研究“平铺”反射,以便它一次呈现一点反射,但我不确定最好的方法是什么。
以下是绘图代码:
UIImage *mask = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"3.0-Carousel-Ref-Mask.jpg" ofType:nil]];
//
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:self.name ofType: nil]];
UIGraphicsBeginImageContextWithOptions(mask.size, NO, [[UIScreen mainScreen]scale]);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, 0.0, mask.size.height);
CGContextScaleCTM(ctx, 1.f, -1.f);
[image drawInRect:CGRectMake(0.f, -mask.size.height, image.size.width, image.size.height)];
UIImage *flippedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef maskRef = mask.CGImage;
CGImageRef maskCreate = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask([flippedImage CGImage], maskCreate);
CGImageRelease(maskCreate);
UIImage *maskedImage = [UIImage imageWithCGImage:masked scale:[[UIScreen mainScreen]scale] orientation:UIImageOrientationUp];
CGImageRelease(masked);
if (maskedImage) {
[mainView performSelectorOnMainThread:@selector(imageDidLoad:)
withObject:[NSArray arrayWithObjects:maskedImage, endView, nil]
waitUntilDone:YES];
} else
NSLog(@"Unable to find sample image: %@", self.name);蒙版只是我用来遮罩图像的渐变png。而且,如果我只是在屏幕外绘制,而不添加它,几乎不会有任何延迟。延迟来自于在主线程上实际添加它。
发布于 2012-10-24 22:53:57
因此,在花了大量时间研究这个问题并尝试了不同的方法之后(并花了一段时间使用Instruments中的" time“分析器),我发现延迟来自于显示图像时主线程上的图像解码。通过在后台对所有CoreGraphics调用进行解码,我能够将时间减半。这仍然不够好。
我进一步发现,由于透明度或alpha像素的原因,在我的代码中创建的反射需要很长时间才能显示。因此,我在上下文中绘制了它,并用纯黑色填充了上下文。然后我使视图本身透明,而不是图像。这减少了在主线程上花费的时间83%-任务完成
https://stackoverflow.com/questions/12904917
复制相似问题