截取当前屏幕图像,并将图片存入沙盒中。

来源:互联网 发布:国培网络研修成果 编辑:程序博客网 时间:2024/06/10 04:00

    CGRect rect = [self.viewbounds];    UIGraphicsBeginImageContext(rect.size);    CGContextRef context =UIGraphicsGetCurrentContext();    [self.view.layerrenderInContext:context];        UIImage *image =UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();       NSData *data = UIImagePNGRepresentation(image);//转换成二进制文件   NSString *path = NSHomeDirectory();   NSLog(@"%@",path);    [data writeToFile:[NSStringstringWithFormat:@"%@/Documents/ss.png",path]atomically:YES];

0 0
原创粉丝点击