gpt4 book ai didi

android - 显示照片的拍摄日期?

转载 作者:行者123 更新时间:2023-11-29 14:28:18 25 4
gpt4 key购买 nike

我想在我的 ImageView 上显示照片的拍摄日期。假设我的 girdview 上有照片。单击它后,它将转到其他 Activity 并显示图像的完整尺寸。现在在该 Activity 中,我需要显示拍摄日期。有什么想法吗?

最佳答案

我认为在 Android 上有两种可能的方法。第一个是文件修改日期,可以这样实现:

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

另一种方法是检查图像上的 EXIF 数据以获取照片的拍摄日期(如果该信息可用):

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(取 self 用 Nexus S 拍摄的图像)

关于android - 显示照片的拍摄日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12478736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com