Ios 获取设备截屏图片

 截取当前屏幕

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

{

UIGraphicsBeginImageContext(CGSizeMake(appWith,appHight-50));

//renderInContext呈现接受者及其子范围到指定的上下文

[view.layerrenderInContext:UIGraphicsGetCurrentContext()];

//返回一个基于当前图形上下文的图片

UIImage*extractImage =UIGraphicsGetImageFromCurrentImageContext();

//移除栈顶的基于当前位图的图形上下文

UIGraphicsEndImageContext();

//以png格式返回指定图片的数据

NSData*imageData =UIImagePNGRepresentation(extractImage);

UIImage*imge = [UIImageimageWithData:imageData];

----------------------------------至此已经得到需要的图片------------------------------------------


主要代码


//根据自己的需要编辑尺寸

floatoriginX =0.0;

floatoriginY =0.0;

floatwidth =appWith;

floatheight =450;

CGRectrect1 =CGRectMake(originX , originY, width ,height);

UIImage* Scrimg = [UIImageimageWithCGImage:CGImageCreateWithImageInRect([imgeCGImage], rect1)];

returnScrimg;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容