如何在动画图像时拍摄UIImageView的屏幕截图

时间:2013-08-19 10:18:18

标签: objective-c uiimageview uiimage

我正在尝试捕捉屏幕,它在图像视图中只有一个图像时效果很好....但是当我为UIImageView设置动画时,我得到一个空白的屏幕截图..

  CGRect rect = [self.view bounds];
  UIGraphicsBeginImageContext(rect.size);
  CGContextRef context = UIGraphicsGetCurrentContext();
  [self.view.layer renderInContext:context];
  UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  UIImageWriteToSavedPhotosAlbum(capturedScreen, nil, nil, nil);

1 个答案:

答案 0 :(得分:0)

我不知道我的回答是对(或)是错的,但我这样尝试了...... i got some code from here 感谢Iphone_bharat

    -(void)change
     {
       if (i>=imags.count-1)
       i=0;
       else
       i++;
     }
    -(void)images      
       {
        NSArray *imagenames = @[@"1.png",@"b.png",@"c.png"];
        int j;
        NSMutableArray *images= [[NSMutableArray alloc]init];
           for (j=0; j<imagenames.count; j++)
               [images addObject:[UIImage imageNamed:[imagenames objectAtIndex:j]]];
        self.imageview1.animationImages = images;
        self.imageview1.animationDuration =1;
        [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(change) userInfo:nil repeats:YES];
        [self.bground startAnimating];
        }
      -(IBAction)captureImage:(id)sender
      {
       self.imageview2.image = [images objectAtIndex:i];
       CGRect rect = [self.view bounds];
       UIGraphicsBeginImageContext(rect.size);
       CGContextRef context = UIGraphicsGetCurrentContext();
       [self.view.layer renderInContext:context];
       UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
       UIGraphicsEndImageContext();
       UIImageWriteToSavedPhotosAlbum(capturedScreen, nil, nil, nil);


      }