UIImage保存为JPG,PNG的方法

View Code
 1 / Create paths to output images
2 NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
3 NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
4
5 // Write a UIImage to JPEG with minimum compression (best quality)
6 // The value 'image' must be a UIImage object
7 // The value '1.0' represents image compression quality as value from 0.0 to 1.0
8 [UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
9
10 // Write image to PNG
11 [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
12
13 // Let's check to see if files were successfully written...
14
15 // Create file manager
16 NSError *error;
17 NSFileManager *fileMgr = [NSFileManager defaultManager];
18
19 // Point to Document directory
20 NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
21
22 // Write out the contents of home directory to console
23 NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);

posted on 2012-02-09 23:55  AXZON  阅读(385)  评论(0编辑  收藏  举报

导航