将UIImage转成PNG/JPG

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容