1

ここに画像の説明を入力してください画面上のビューをキャプチャするために次のコードを使用していますが、画面上ほど鮮明ではありません。imageViewのサイズは200x200ポイントですが、スケールは2.0です(網膜スクリーンを使用)。保存imgされるサイズは200x200ピクセルです。どうすればimg元のシャープと同じくらいシャープにすることができますか?どんな助けでもありがたいです!

- (UIImage*)captureView:(UIView *)theView {

    CGRect rect = theView.frame;
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [theView.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}
4

2 に答える 2

3

そのようにしてみてください:

     CGRect screenRect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
于 2012-12-12T04:44:27.937 に答える
1

画像コンテキストを作成する古い方法を使用しています。代わりにこれを使用してください:

UIGraphicsBeginImageContextWithOptions(rect.size, YES, [UIScreen mainScreen].scale);

古いUIGraphicsBeginImageContext関数は常に1.0のスケールを想定しています。

アルファチャネルが必要な場合は、「YES」を「NO」に置き換えます。

于 2012-12-12T04:42:41.240 に答える