0

iOS で UIView スクリーン キャプチャを取得しようとしています。

私の見解では、アニメーション付きの 2 つの UIImageView があります。

ビューをキャプチャするために使用するコードは次のとおりです。

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 1.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
// Read the UIImage object
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(image, self,
                               @selector(image:didFinishSavingWithError:contextInfo:), nil);

結果は、背景と 1 つの UIImageView のみを持つイメージです。両方の ImageView は常に動いています。複数の写真を撮る場合、UIImageView は毎回同じ位置にあります。

4

1 に答える 1

2

これを試してください:

-(CGImageRef)imageCapture
{
   UIGraphicsBeginImageContext(self.view.bounds.size);
   [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
   UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();
   CGRect rect= CGRectMake(0,0 ,width, height);

   CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], rect);
   return imageRef;
}

画面をキャプチャしたいときはいつでも以下の行を使用してください

UIImage *captureImg=[[UIImage alloc] initWithCGImage:[self imageCapture]];
于 2013-03-06T21:31:12.160 に答える