【发布时间】:2013-01-24 22:57:24
【问题描述】:
我有一个绘图应用程序,我想创建 Canvas UIView(屏幕上和屏幕外)的快照,然后将其缩小。我在 iPad 3 上执行此操作的代码永远是血腥的。模拟器没有延迟。画布为 2048x2048。
还有其他方法我应该这样做吗?还是我在代码中遗漏了什么?
谢谢!
-(UIImage *) createScreenShotThumbnailWithWidth:(CGFloat)width{
// Size of our View
CGSize size = editorContentView.bounds.size;
//First Grab our Screen Shot at Full Resolution
UIGraphicsBeginImageContext(size);
[editorContentView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Calculate the scal ratio of the image with the width supplied.
CGFloat ratio = 0;
if (size.width > size.height) {
ratio = width / size.width;
} else {
ratio = width / size.height;
}
//Setup our rect to draw the Screen shot into
CGSize newSize = CGSizeMake(ratio * size.width, ratio * size.height);
//Send back our screen shot
return [self imageWithImage:screenShot scaledToSize:newSize];
}
【问题讨论】:
-
重要的是要记住,模拟器只是一个模拟器,而不是 iPad、iPhone 或 iPod 性能的真实代表。那里的任何代码都可以访问您计算机的全部资源,这将比 iPad 3 强大得多。正如下面 AliSoftware 提到的,在尝试绘制图像之前缩放图像可能是一个更好的主意,这样你就可以剪掉你目前正在做的工作的大约 50%。
标签: ios xcode uiimage thumbnails