它显示拍摄时,图像的日期? [英] Display the date of the picture when it was taken?

查看:130
本文介绍了它显示拍摄时,图像的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示图片的日期,当它被带到我的ImageView的,比方说,我有我的照片girdview。一旦我点击它,它会去其他活动并显示图像的完整大小。现在,在活动中,我需要显示它拍摄时的日期。任何想法?

I want to display the date of the picture when it was taken on my ImageView., Let's say that I have pictures on my girdview. once I clicked it, it'll go to other activity and display the full size of the image. Now in that activity, I need to display the date when it was taken. Any Ideas?

推荐答案

有两种可能的方式,我可以看到在Android这样做的。它可以像这样实现第一个是文件的修改日期:

There are two possible ways I can see of doing this on Android. The first being the file modified date which can be achieved like so:

String pathToFile = "Your file path";
File file = new File(pathToFile);
if(file.exists()) {
    long date = file.lastModified();
    /* Do your modified date stuff here */
}

另一种方法是检查图像上的EXIF数据中得到的图片拍摄的日期,如果这些信息可用:

The other way would be to check the EXIF data on the image to get the date the picture was taken if that information is available:

ExifInterface intf = null;
try {
    intf = new ExifInterface(path);
} catch(IOException e) {
    e.printStackTrace();
}

if(intf == null) {
    /* File doesn't exist or isn't an image */
}

String dateString = intf.getAttribute(ExifInterface.TAG_DATETIME);
/* Do your date/time stuff here */

刚一说明,对于图像可能不包含日期的EXIF数据。大多数手机相机和商业摄像机将添加的日期/时间的Exif条目而是在计算机上创建的图像是不太可能有Exif数据中。此外,的Exif日期/时间未格式化很不错。示例的Exif日期/时间字符串: 2012:06:02 14时33分46秒(从我带着我的歌Nexus S的图像拍摄)

Just a note, the Exif data for an image might not contain a date. Most phone cameras and commercial cameras will add a date/time Exif entry but images created on a computer are less likely to have Exif data. Also, Exif date/time isn't formatted very nice. Example Exif date/time string: 2012:06:02 14:33:46 (taken from an image I took with my Nexus S)

这篇关于它显示拍摄时,图像的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆