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; 
}
4

1 に答える 1

15

UIGraphicsBeginImageContextWithOptionsの代わりに使用UIGraphicsBeginImageContext:

UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);

詳細については、 Apple QA1703を参照してください。

于 2010-12-26T15:14:28.733 に答える