将UIView转成UIImage,将UIImage转成PNG/JPG
来源:互联网 发布:防木马软件 编辑:程序博客网 时间:2024/06/05 05:08
- //把UIView 转换成图片
- -(UIImage *)getImageFromView:(UIView *)view{
- UIGraphicsBeginImageContext(view.bounds.size);
- [view.layer renderInContext:UIGraphicsGetCurrentContext()];
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return image;
- }
- //UIImage -> PNG / JPG
- // Create paths to output images
- NSString*pngPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
- NSString*jpgPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
- // Write a UIImage to JPEG with minimum compression (best quality)
- // The value 'image' must be a UIImage object
- // The value '1.0' represents image compression quality as value from 0.0 to 1.0
- [UIImageJPEGRepresentation(image,1.0) writeToFile:jpgPath atomically:YES];
- // Write image to PNG
- [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
- // Let's check to see if files were successfully written...
- // Create file manager
- NSError*error;
- NSFileManager*fileMgr=[NSFileManager defaultManager];
- // Point to Document directory
- NSString*documentsDirectory=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
- // Write out the contents of home directory to console
- NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
0 0
- 将UIView转成UIImage,将UIImage转成PNG/JPG
- 将UIView转成UIImage,将UIImage转成PNG/JPG
- IOS 将UIView转成UIImage
- UIView转成UIImage
- 将UIImage对象保存到JPG或者PNG文件中
- 如何将.jpg 转成.eps
- 将yuv转成png图
- 如何把UIView转成UIImage,解决模糊失真问题
- 把UIView转成UIImage,解决模糊失真问题
- 如何把UIView转成UIImage,解决模糊失真问题
- 如何把UIView转成UIImage,解决模糊失真问题
- UIView 转化为 UIImage,将UIImage 保存到沙盒中
- 怎样将UIImage对象保存到JPG或者PNG文件中?
- iphone 怎样将UIImage对象保存到JPG或者PNG文件中?
- 怎样将UIImage对象保存到JPG或者PNG文件中?
- IOS将UIView转化为UIImage
- UIImage图片转成Base64字符串
- 怎样将jpg转成pdf格式
- Linux驱动之设备模型(4)-总线
- Oracle死锁问题分析解决
- WARN No appenders could be found for logger的解决方法
- Spring-AOP-Struts重新解析
- Codeforces 401B Sereja and Contests(水题)
- 将UIView转成UIImage,将UIImage转成PNG/JPG
- 三 Gazebo学习总结之制作一个模型及导入网格
- 关于leveldb
- python socket文件通信练习
- Linux驱动之设备模型(5)-设备
- HTML meta viewport属性说明
- gzip的介绍以及web服务器对文件压缩的支持
- 第一周:算法概论
- 过滤器与拦截器的具体区别