如何从图片中获取日期和文件大小?
问题描述:
如果从相册中将图片加载到应用程序中,如何获取以 MB 为单位的文件大小以及该图片在应用程序上显示的日期(如下面的屏幕截图所示)?
If pictures are loaded into an app from a album, how is it possible to get the filesize in MB and the date of that picture displayed on a app like on the screenshot below?
我知道您可以使用以下代码通过 NSLog 检索文件大小,但是我如何将其转换为字符串以及该图片的日期?
I know you can retrieve the filesize via a NSLog using the following code, but how can I get this into a string and also the date of that picture?
NSLog(@"size of image in KB: %i",[UIImagePNGRepresentation(UIImage) length]);
答
使用 CoreGraphics
Use CoreGraphics
size_t imageSize = CGImageGetBytesPerRow(image.CGImage) * CGImageGetHeight(image.CGImage);