0

我正在尝试捕获屏幕,当它在图像视图中只有一个图像时它工作得很好..但是当我为 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);
4

1 回答 1

0

我不知道我的回答是否正确(或)错误,但我尝试过这样...... 感谢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);


      }
于 2013-08-21T09:32:16.517 回答