che*_*ewy 3 iphone cocoa-touch jpeg screen-capture
亲爱的学者我正在使用以下代码捕获屏幕并将其保存到相册内的jpg - 这非常有用.
然而,当在具有更高分辨率的iPhone 4上运行时,捕获的屏幕仅为320X480而不是更高的分辨率(我认为在iPad上也是如此).
我应该如何解决这个问题?
// Save the captured image to photo album
- (IBAction)saveAsJPG
{
UIImage *image = [self captureView:self.view];
UIImageWriteToSavedPhotosAlbum(image, self,
@selector(image:didFinishSavingWithError:contextInfo:), nil);
}
-(UIImage *)captureView:(UIView *)view
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[view.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Run Code Online (Sandbox Code Playgroud)
小智 15
使用UIGraphicsBeginImageContextWithOptions而不是UIGraphicsBeginImageContext:
UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅Apple QA1703.
| 归档时间: |
|
| 查看次数: |
2773 次 |
| 最近记录: |