相关代码:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41import java.io.File; import com.drew.imaging.ImageMetadataReader; import com.drew.metadata.Directory; import com.drew.metadata.Metadata; import com.drew.metadata.exif.ExifSubIFDDirectory; public class TestFileTwo { public static void main(String[] args) throws Exception{ changeFile(new File("E:\test")); } static void changeFile(File file) throws Exception { if (file.isFile()) { Metadata metadata = ImageMetadataReader.readMetadata(file); for (Directory directory : metadata.getDirectories()) { if("ExifSubIFDDirectory".equalsIgnoreCase( directory.getClass().getSimpleName() )){ String time1 = directory.getString(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL); String time2 = time1.replace( ':','-' ); String rootPath = file.getParent(); String filename = file.getName(); String substring = ""; if ((filename != null) && (filename.length() > 0)) { int dot = filename.lastIndexOf('.'); if ((dot >-1) && (dot < (filename.length() - 1))) { substring = filename.substring(dot + 1); } } File newFile = new File(rootPath + File.separator + time2 + "." + substring); file.renameTo(newFile); } } } else { File[] files = file.listFiles(); for (File filealone : files) changeFile(filealone); } } }
主要参考:
http://blog.csdn.net/wang_zhenwei/article/details/71172975
http://blog.csdn.net/wang_zhenwei/article/details/60968265
最后
以上就是有魅力鼠标最近收集整理的关于图像处理4_使用 metadata-extractor 修改图片名为拍摄时间的全部内容,更多相关图像处理4_使用内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复