在Retina / 高分辨率屏幕上进行程序化屏幕截图

3
亲爱的学者们, 我正在使用以下代码来捕捉屏幕并将其保存为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; 
}
1个回答

15
使用UIGraphicsBeginImageContextWithOptions代替UIGraphicsBeginImageContext:
UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);

详细信息请参见Apple QA1703


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接