IOS截屏

最近,在找IOS截屏的方法。找到一个,现在记录下来。跟我想的差不多,还是,进入操作(初始化),操作(复制当前屏幕,保存),退出。最小的操作结构。

1 . 先指定图像的大小

UIGraphicsBeginImageContext(view.frame.size);

2. 在指定的区域绘制图像

[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];

3. 获取图像上下文

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

4. 关闭图像上下文

UIGraphicsEndImageContext();

没错!只需要4行代码就可以获取到指定View的图像截图。

另外,常用的绘制图像还有另一个方法:

[view.layer renderInContext:UIGraphicsGetCurrentContext()];
+ (UIImage *)getImageViewWithView:(UIView *)view
{
    UIGraphicsBeginImageContext(view.frame.size);
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

代码还是对现实世界的一个简单映射啊。只能做简单重复的操作。影响开发能力的还是人自己啊。

时间: 2024-08-07 08:39:45

IOS截屏的相关文章

ios 截屏

把当前屏幕作为获取成为图片 - (UIImage *)rn_screenshot {    UIGraphicsBeginImageContext(self.bounds.size);    [self.layer renderInContext:UIGraphicsGetCurrentContext()];    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext(

IOS截屏,View截图的基本方法

IOS截屏的方法网上有很多,以下是我个人认为比较好的一个,我稍微改了一点 来源:SDScreenshotCapture #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) UIImage *getImageWithFullScreenshot(vo

ios截屏代码[转]

http://www.cnblogs.com/chenxiangxi/p/3547974.html 这位博主的连接中将ios自定义大小位置的截屏代码写的很不错,马上就能用的方法,对于只想马上用的程序员很有帮助 http://www.2cto.com/kf/201310/250228.html 我将其改为以下代码: 1 #pragma mark -=====自定义截屏位置大小的逻辑代码=====- 2 static int ScreenshotIndex=0; //这里的逻辑直接采用上面博主的逻辑

iOS截屏保存至相册

#pragma mark 截屏并保存至相册 -(void)screenShotsComplete:(void(^)(UIImage * img)) complete { CGSize imageSize = [[UIScreen mainScreen] bounds].size; UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(

ios 截屏(代码)

//1.首先在storyboard中拖一些控件,包括UIButton控件,将UIButton控件拖线到控制器中(方法.CutImage) //2.在CutImage方法中调用NSTimer方法 - (IBAction)CutImage:(UIButton *)sender { NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 targer:self  selector:@selector(clipImage) userInf

iOS截屏代码

/** *截图功能 */ -(void)screenShot{ UIGraphicsBeginImageContextWithOptions(CGSizeMake(640, 960), YES, 0); //设置截屏大小 [[self.view layer] renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGrap

ios截屏使用的方法

- (UIImage*)getimage{//截屏使用的方法CGSize imageSize = [[UIScreen mainScreen] bounds].size;if (NULL != UIGraphicsBeginImageContextWithOptions) {UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);} else {UIGraphicsBeginImageContext(imageSize);}CGConte

iOS 截屏以及相关扩展(UIImage的绘制和渲染)

1.截取当前屏幕 CGSize windowSize = behandView.bounds.size; UIGraphicsBeginImageContextWithOptions(windowSize, YES, 2.0); CGContextRef context = UIGraphicsGetCurrentContext(); [behandView.window.layer renderInContext:context]; UIImage *snapshot = UIGraphics

iOS 截屏功能的实现

#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } -(void)touchesEnded:(NSSet *)touche