我有一個繪圖應用程序的種類,我想創建一個Canvas UIView的快照(在屏幕上和屏幕上),然後將其縮小。我所做的代碼在iPad 3上永遠不會流血。模擬器沒有任何延遲。畫布是2048x2048。捕獲UIView的屏幕截圖 - 慢速性能
有沒有另一種方法我應該這樣做?或者我在代碼中錯過了一些東西?
謝謝!
-(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%。 – 2013-02-09 12:38:50