【发布时间】:2013-08-28 01:59:39
【问题描述】:
要求是捕获显示为 UIImage 的屏幕内容,然后对该图像执行自定义关闭动画。
【问题讨论】:
-
模拟器运行时按 Command + S 按钮。 :) 它会将完整的模拟器照片保存在桌面上。
标签: ios objective-c iphone uiimage
要求是捕获显示为 UIImage 的屏幕内容,然后对该图像执行自定义关闭动画。
【问题讨论】:
标签: ios objective-c iphone uiimage
这段代码将为您提供所传递视图的 UIImage。要获取整个屏幕的图像,请在您的一些 UIViewController 中传递 self.view
- (UIImage*)screenShotOfView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
【讨论】:
第一个,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);
}
【讨论】:
按 Command + Shift + 4 然后选择模拟器,快照将保存在您的桌面,然后将保存的图像拖到模拟器并在 safari 上打开...长选项卡保存图像...现在您可以从模拟器上的照片库中获取图像。
【讨论】:
- (UIImage*)screenShotOfView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } 保存使用此UIImageWriteToSavedPhotosAlbum([self captureView:view], nil, nil, nil);@lucas-eduardo 说...我认为这是唯一的方法