ios开发-屏幕截图(UIView转为图像存储到本地)

来源:互联网 发布:apache开源社区 编辑:程序博客网 时间:2024/06/05 19:06
屏幕截图(UIView转为图像存储到本地)


在做课设的时候,涉及到了一个功能,类似屏幕截图一样,把当前视图裁剪下来,当做图片寸到本地相册。

实现起来很简单,几行代码的事。
下面直接上代码了。

1.在头文件导入库。

#import <QuartzCore/QuartzCore.h>


2.在.m中实现方法。

    

    UIGraphicsBeginImageContext(self.view.bounds.size);

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(image,self,nil,nil);




学习的路上,与君共勉。
原创粉丝点击