截图

来源:互联网 发布:重生之网络娱乐小说 编辑:程序博客网 时间:2024/05/16 21:24
//这里返回的是一张图片 根据所给颜色返回一张此颜色的图片+ (UIImage *)convertColorToImage:(UIColor *)color {    CGRect rect = CGRectMake(0, 0, 1, 1);    //设置截取的大小    UIGraphicsBeginImageContext(rect.size);    //    CGContextRef context = UIGraphicsGetCurrentContext();    CGContextSetFillColorWithColor(context, [color CGColor]);    //    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    //    return theImage;}//根据图层进行截图-(UIImage *)screenShots{    //截图     //设置大小    UIGraphicsBeginImageContext(shareImageView.frame.size);    //选择要截取的图层(自己想要截取的view)    [shareImageView.layer renderInContext:UIGraphicsGetCurrentContext()];    //得到截取的图片    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();   //UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);(将截图保存到相册中)    return viewImage;}
0 0
原创粉丝点击