3. //UIImage -> PNG / JPG
4. // Create paths to output images
5. NSString
6. *pngPath
7. =
8. [NSHomeDirectory()
9. stringByAppendingPathComponent:@"Documents/Test.png"];
10. NSString
11. *jpgPath
12. =
13. [NSHomeDirectory()
14. stringByAppendingPathComponent:@"Documents/Test.jpg"];
15.
16. // Write a UIImage to JPEG with minimum compression (best quality)
17. // The value 'image' must be a UIImage object
18. // The value '1.0' represents image compression quality as value from 0.0 to 1.0
19.
20. [UIImageJPEGRepresentation(image,
21. 1.0) writeToFile:jpgPath
22. atomically:YES];
23.
24. // Write image to PNG
25. [UIImagePNGRepresentation(image)
26. writeToFile:pngPath atomically:YES];
27.
28. // Let's check to see if files were successfully written...
29. // Create file manager
30. NSError
31. *error;
32. NSFileManager
33. *fileMgr
34. =
35. [NSFileManager defaultManager];
36.
37. // Point to Document directory
38. NSString
39. *documentsDirectory
40. =
41. [NSHomeDirectory()
42. stringByAppendingPathComponent:@"Documents"];
43.
44. // Write out the contents of home directory to console
网友评论