iOS

来源:互联网 发布:淘宝刷单详细流程图 编辑:程序博客网 时间:2024/05/28 04:53

其中有一个必须的参数,类型是 UIView * ,这个参数表示您要截取的那部分视图。有两个方法,一个是截取该视图的整个部分,还要一个方法是截取该视图的某一部分,方法如下:



//获得某个范围内的屏幕图像

- (UIImage *)captureScreenForView:(UIView *)currentView andFrame:(CGRect)rect

{

    UIGraphicsBeginImageContext(currentView.frame.size);

    CGContextRef context =UIGraphicsGetCurrentContext();

    CGContextSaveGState(context);

    UIRectClip(rect);

    [currentView.layerrenderInContext:context];

    UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return  theImage;

}


// 截取全屏

-(UIImage *)captureScreenForView:(UIView *)currentView {

    UIGraphicsBeginImageContext(currentView.frame.size);

    [currentView.layerrenderInContext:UIGraphicsGetCurrentContext()];

    UIImage *viewImage =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return  viewImage;

}



原创粉丝点击