0

我正在使用以下代码将 UIView 捕获为图像

-(void)startSnapSot {
    NSLog(@"TakeSnapShot");

        UIImage* image = nil;

        //   image = [self screenshot];
        UIGraphicsBeginImageContext(overlayView.frame.size);
        {
            [overlayView.layer renderInContext: UIGraphicsGetCurrentContext()];
            image = UIGraphicsGetImageFromCurrentImageContext();
        }
        UIGraphicsEndImageContext();

        ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) {
            if (error) {
                NSLog(@"Error Saving Image");
            }
            else {
                NSLog(@"Image Saved");
            }
        };

        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library writeImageToSavedPhotosAlbum:[image CGImage]
                                  orientation:(ALAssetOrientation)[image imageOrientation]
                              completionBlock:completionBlock];
}

但问题是它一次又一次地保存第一张图像,即它一次又一次地保存相同的图像而不是捕获不同的 UIIView 图像。有人可以让我知道我在做什么错吗?

4

0 回答 0