Newer
Older
restamp / src / main / java / osm / surveyor / util / Exif.java
@haya4 haya4 on 26 Jan 2020 2 KB Restamp
  1. package osm.surveyor.util;
  2.  
  3. import java.io.*;
  4. import java.text.DateFormat;
  5. import java.text.ParseException;
  6. import java.text.SimpleDateFormat;
  7. import java.util.Date;
  8. import java.util.TimeZone;
  9.  
  10. public class Exif extends Thread {
  11. public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss'Z'";
  12. private static final String EXIF_DATE_TIME_FORMAT_STRING = "yyyy:MM:dd HH:mm:ss";
  13. /**
  14. * 対象は '*.JPG' のみ対象とする
  15. * @return
  16. * @param name
  17. */
  18. public static boolean checkFile(String name) {
  19. return ((name != null) && name.toUpperCase().endsWith(".JPG"));
  20. }
  21.  
  22. /**
  23. * DateをEXIFの文字列に変換する。
  24. * 注意:EXiFの撮影時刻はUTC時間ではない
  25. * @param localdate
  26. * @return
  27. */
  28. public static String toEXIFString(Date localdate) {
  29. DateFormat dfUTC = new SimpleDateFormat(EXIF_DATE_TIME_FORMAT_STRING);
  30. return dfUTC.format(localdate);
  31. }
  32. /**
  33. * EXIFの文字列をDateに変換する。
  34. * 注意:EXiFの撮影時刻はUTC時間ではない
  35. * @param timeStr
  36. * @return
  37. * @throws ParseException
  38. */
  39. public static Date toEXIFDate(String timeStr) throws ParseException {
  40. DateFormat dfUTC = new SimpleDateFormat(EXIF_DATE_TIME_FORMAT_STRING);
  41. //dfUTC.setTimeZone(TimeZone.getTimeZone("UTC"));
  42. return dfUTC.parse(timeStr);
  43. }
  44. public static String toUTCString(Date localdate) {
  45. DateFormat dfUTC = new SimpleDateFormat(TIME_FORMAT_STRING);
  46. dfUTC.setTimeZone(TimeZone.getTimeZone("UTC"));
  47. return dfUTC.format(localdate);
  48. }
  49. public static Date toUTCDate(String timeStr) throws ParseException {
  50. DateFormat dfUTC = new SimpleDateFormat(TIME_FORMAT_STRING);
  51. dfUTC.setTimeZone(TimeZone.getTimeZone("UTC"));
  52. return dfUTC.parse(timeStr);
  53. }
  54. static String getShortPathName(File dir, File iFile) {
  55. String dirPath = dir.getAbsolutePath();
  56. String filePath = iFile.getAbsolutePath();
  57. if (filePath.startsWith(dirPath)) {
  58. return filePath.substring(dirPath.length()+1);
  59. }
  60. else {
  61. return filePath;
  62. }
  63. }
  64. /**
  65. * JPEGファイルフィルター
  66. * @author yuu
  67. */
  68. class JpegFileFilter implements FilenameFilter {
  69. @Override
  70. public boolean accept(File dir, String name) {
  71. return name.toUpperCase().matches(".*\\.JPG$");
  72. }
  73. }
  74. }