【问题标题】:iOS capture UIView with UIImageView insideiOS 用 UIImageView 捕获 UIView
【发布时间】:2013-03-06 17:41:26
【问题描述】:

我正在尝试在 iOS 上获取 UIView 屏幕截图。

在我看来,我有两个带有动画的 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);

结果是一张有背景的图片,只有一个 UIImageView。两个 ImageView 一直在移动。如果我拍了几张照片,那么 UIImageView 每次都在同一个位置。

【问题讨论】:

  • 使用self.view.layer.presentationLayer

标签: ios uiview uiimageview image-capture


【解决方案1】:

试试这个:

-(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]];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多