将UIImage对象保存到JPG或者PNG文件中
2012-05-24 16:48
423 查看
from:http://blog.csdn.net/wherejaly/article/details/5538248
如果要从data中或者file中读取数据并包装成UIImage可以使用+ imageWithData: 和+ imageWithContentsOfFile: 但如果想把UIImage的图片数据写入到jpg或者png格式的文件中呢?答案是UIImageJPEGRepresentation,请看如下代码
[cpp] view
plaincopy
/ 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]);
参考资料:http://iphonedevelopertips.com/data-file-management/save-uiimage-object-as-a-png-or-jpeg-file.html
如果要从data中或者file中读取数据并包装成UIImage可以使用+ imageWithData: 和+ imageWithContentsOfFile: 但如果想把UIImage的图片数据写入到jpg或者png格式的文件中呢?答案是UIImageJPEGRepresentation,请看如下代码
[cpp] view
plaincopy
/ 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]);
参考资料:http://iphonedevelopertips.com/data-file-management/save-uiimage-object-as-a-png-or-jpeg-file.html
相关文章推荐
- 怎样将UIImage对象保存到JPG或者PNG文件中?
- 怎样将UIImage对象保存到JPG或者PNG文件中?
- iphone 怎样将UIImage对象保存到JPG或者PNG文件中?
- 绘制bitmap图片保存,生成ico文件或者对象
- iPhone UIImage保存到文件,PNG/JPEG自适应
- 更新系统或者更换Eclipse后,双击Eclipse-drawable,或者在布局文件中,查看图片时,显示乱码。png 和 jpg
- iPhone UIImage保存到文件,PNG/JPEG自适应
- easyWeb2Pic -- 在IE浏览器中,将整个网页保存为BMP, JPEG/JPG, GIF, PNG或者TIFF图片
- VC屏幕截图并保存为bmp、jpg、png等格式文件
- iPhone UIImage保存到文件,PNG/JPEG自适应
- JPG,PNG等格式的图片转换的ICON保存为ICO文件
- VC屏幕截图并保存为bmp、jpg、png等格式文件
- iPhone UIImage保存到文件,PNG/JPEG自适应
- UIImage保存成png和jpg
- JPG,PNG等格式的图片转换的ICON保存为ICO文件
- VB6.0用GDI+保存图片为JPG、TIFF、PNG、GIF、BMP等格式
- 使用 Video4Linux 采集USB摄像头的图像,并保存到一张 jpg图像文件中的程序
- Linux下批量修改文件名的后缀 例如 .png文件修改为.jpg文件
- vc6.0使用gdi+在内存中绘图并将其保存为bmp,jpg,gif,png等格式的图片
- C#将文件保存到数据库中或者从数据库中读取文件