从iOS视图捕获图像

时间:2013-11-07 13:20:26

标签: ios alassetslibrary uigraphicscontext

我使用以下代码将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图像。可以有人让我知道我在做什么错吗?

0 个答案:

没有答案