-6

要求是捕获显示为 UIImage 的屏幕内容,然后对该图像执行自定义关闭动画。

4

3 回答 3

2

这段代码将为您提供所传递视图的 UIImage。要获取整个屏幕的图像,请传入self.view您的一些 UIViewController

- (UIImage*)screenShotOfView:(UIView *)view
{
     UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
     [view.layer renderInContext:UIGraphicsGetCurrentContext()];
     UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext();

     return image;
}
于 2013-08-25T15:19:42.617 回答
0

第一个,captureView,返回一个 UIImage,其中包含任何 UIView 的渲染(EAGLView 除外,见下文)。如果您将应用程序的 UIWindow 传递给此方法,它将返回应用程序的屏幕截图。

第二种方法 saveScreenshotToPhotosAlbum 更进一步,将包含任何 UIView 渲染的图像保存到 iPhone 的相册中。

- (UIImage*)captureView:(UIView *)view 

{

        CGRect rect = [[UIScreen mainScreen] bounds];
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [view.layer renderInContext:context];
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return img;

}



(void)saveScreenshotToPhotosAlbum:(UIView *)view 
{

        UIImageWriteToSavedPhotosAlbum([self captureView:view], nil, nil, nil);
}
于 2013-08-25T15:43:26.300 回答
-1

Press Command + Shift + 4 then select the simulator and snapshot will be saved at your desktop, then drag the saved image to the simulator and will open on safari ... long tab to save image ... and now u can get the image from photos library on simulator.

于 2013-08-25T13:59:41.557 回答