Ste*_*lla 1 android date imageview
我希望在我的ImageView上显示照片的日期.让我们说我的照片上有照片.一旦我点击它,它将转到其他活动并显示图像的完整大小.现在,在该活动中,我需要显示拍摄日期.有任何想法吗?
我可以通过两种方式在Android上看到这样做.第一个是文件修改日期,可以像这样实现:
String pathToFile = "Your file path";
File file = new File(pathToFile);
if(file.exists()) {
long date = file.lastModified();
/* Do your modified date stuff here */
}
Run Code Online (Sandbox Code Playgroud)
另一种方法是检查图像上的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 */
Run Code Online (Sandbox Code Playgroud)
请注意,图像的Exif数据可能不包含日期.大多数手机摄像头和商用摄像头都会添加日期/时间Exif条目,但在计算机上创建的图像不太可能有Exif数据.此外,Exif日期/时间格式不是很好.示例Exif日期/时间字符串:( 2012:06:02 14:33:46取自我用Nexus S拍摄的图像)
| 归档时间: |
|
| 查看次数: |
18542 次 |
| 最近记录: |