質問編集履歴

4

修正不要になったため

2018/05/02 06:26

投稿

sobue
sobue

スコア329

test CHANGED
File without changes
test CHANGED
@@ -305,183 +305,3 @@
305
305
  ```
306
306
 
307
307
  [参考HP](https://ameblo.jp/smd310/entry-10854275741.html)
308
-
309
-
310
-
311
-
312
-
313
- 修正後のソース【完成版】
314
-
315
- ```java
316
-
317
- package main;
318
-
319
-
320
-
321
- import java.io.File;
322
-
323
- import java.io.IOException;
324
-
325
- import java.util.Date;
326
-
327
- import java.util.Iterator;
328
-
329
-
330
-
331
- import com.drew.imaging.jpeg.JpegMetadataReader;
332
-
333
- import com.drew.imaging.jpeg.JpegProcessingException;
334
-
335
- import com.drew.metadata.Directory;
336
-
337
- import com.drew.metadata.Metadata;
338
-
339
- import com.drew.metadata.MetadataException;
340
-
341
- import com.drew.metadata.Tag;
342
-
343
- import com.drew.metadata.exif.ExifDirectoryBase;
344
-
345
- import com.drew.metadata.exif.ExifSubIFDDirectory;
346
-
347
-
348
-
349
- public class Test {
350
-
351
-
352
-
353
- public static void main(String[] args) {
354
-
355
- // TODO 自動生成されたメソッド・スタブ
356
-
357
-
358
-
359
- try {
360
-
361
- // 画像ファイル
362
-
363
- File file = new File("C:/Users/naoya/Desktop/2016_10_12/IMG_7863.jpg");
364
-
365
-
366
-
367
- // 色んなデータを出力してみる
368
-
369
- viewAllData(file);
370
-
371
- // 項目指定したデータを出力してみる
372
-
373
- viewSomeData(file);
374
-
375
- // 撮影日時をDate型で出力してみる
376
-
377
- viewDateData(file);
378
-
379
- } catch (Exception e) {
380
-
381
- e.printStackTrace();
382
-
383
- }
384
-
385
- }
386
-
387
-
388
-
389
- @SuppressWarnings("unchecked")
390
-
391
- public static void viewAllData(File file) throws JpegProcessingException {
392
-
393
- Metadata metadata = null;
394
-
395
- try {
396
-
397
- metadata = JpegMetadataReader.readMetadata(file);
398
-
399
- } catch (IOException e) {
400
-
401
- // TODO 自動生成された catch ブロック
402
-
403
- e.printStackTrace();
404
-
405
- }
406
-
407
- Iterator<Directory> directories = metadata.getDirectories().iterator();
408
-
409
- while (directories.hasNext()) {
410
-
411
- Directory directory = directories.next();
412
-
413
- Iterator<Tag> tags = directory.getTags().iterator();
414
-
415
- while (tags.hasNext()) {
416
-
417
- Tag tag = tags.next();
418
-
419
- System.out.println(tag);
420
-
421
- }
422
-
423
- }
424
-
425
- }
426
-
427
-
428
-
429
- public static void viewSomeData(File file) throws JpegProcessingException {
430
-
431
- ExifDirectoryBase directory = null;
432
-
433
- try {
434
-
435
- directory = JpegMetadataReader.readMetadata(file).getFirstDirectoryOfType(ExifDirectoryBase.class);
436
-
437
- } catch (IOException e) {
438
-
439
- // TODO 自動生成された catch ブロック
440
-
441
- e.printStackTrace();
442
-
443
- }
444
-
445
- // 装置の製造元
446
-
447
- System.out.println(directory.getString(ExifSubIFDDirectory.TAG_MAKE));
448
-
449
- // カメラのモデル
450
-
451
- System.out.println(directory.getString(ExifSubIFDDirectory.TAG_MODEL));
452
-
453
- // 写真の撮影日
454
-
455
- System.out.println(directory.getString(ExifSubIFDDirectory.TAG_DATETIME));
456
-
457
- }
458
-
459
-
460
-
461
- public static void viewDateData(File file) throws JpegProcessingException, MetadataException {
462
-
463
- Metadata metadata = null;
464
-
465
- try {
466
-
467
- metadata = JpegMetadataReader.readMetadata(file);
468
-
469
- ExifSubIFDDirectory subIf = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
470
-
471
- Date date = subIf.getDateOriginal();
472
-
473
- System.out.println(date.toString());
474
-
475
- } catch (IOException e) {
476
-
477
- // TODO 自動生成された catch ブロック
478
-
479
- e.printStackTrace();
480
-
481
- }
482
-
483
- }
484
-
485
- }
486
-
487
- ```

3

完成版

2018/05/02 06:26

投稿

sobue
sobue

スコア329

test CHANGED
File without changes
test CHANGED
@@ -340,6 +340,8 @@
340
340
 
341
341
  import com.drew.metadata.Tag;
342
342
 
343
+ import com.drew.metadata.exif.ExifDirectoryBase;
344
+
343
345
  import com.drew.metadata.exif.ExifSubIFDDirectory;
344
346
 
345
347
 
@@ -368,7 +370,7 @@
368
370
 
369
371
  // 項目指定したデータを出力してみる
370
372
 
371
- // viewSomeData(file);
373
+ viewSomeData(file);
372
374
 
373
375
  // 撮影日時をDate型で出力してみる
374
376
 
@@ -426,11 +428,11 @@
426
428
 
427
429
  public static void viewSomeData(File file) throws JpegProcessingException {
428
430
 
429
- Directory directory = null;
431
+ ExifDirectoryBase directory = null;
430
-
432
+
431
- try {
433
+ try {
432
-
434
+
433
- directory = JpegMetadataReader.readMetadata(file).getFirstDirectoryOfType(ExifSubIFDDirectory.class);
435
+ directory = JpegMetadataReader.readMetadata(file).getFirstDirectoryOfType(ExifDirectoryBase.class);
434
436
 
435
437
  } catch (IOException e) {
436
438
 
@@ -482,6 +484,4 @@
482
484
 
483
485
  }
484
486
 
485
-
486
-
487
487
  ```

2

修正後ソースの追加

2018/05/02 06:20

投稿

sobue
sobue

スコア329

test CHANGED
File without changes
test CHANGED
@@ -305,3 +305,183 @@
305
305
  ```
306
306
 
307
307
  [参考HP](https://ameblo.jp/smd310/entry-10854275741.html)
308
+
309
+
310
+
311
+
312
+
313
+ 修正後のソース【完成版】
314
+
315
+ ```java
316
+
317
+ package main;
318
+
319
+
320
+
321
+ import java.io.File;
322
+
323
+ import java.io.IOException;
324
+
325
+ import java.util.Date;
326
+
327
+ import java.util.Iterator;
328
+
329
+
330
+
331
+ import com.drew.imaging.jpeg.JpegMetadataReader;
332
+
333
+ import com.drew.imaging.jpeg.JpegProcessingException;
334
+
335
+ import com.drew.metadata.Directory;
336
+
337
+ import com.drew.metadata.Metadata;
338
+
339
+ import com.drew.metadata.MetadataException;
340
+
341
+ import com.drew.metadata.Tag;
342
+
343
+ import com.drew.metadata.exif.ExifSubIFDDirectory;
344
+
345
+
346
+
347
+ public class Test {
348
+
349
+
350
+
351
+ public static void main(String[] args) {
352
+
353
+ // TODO 自動生成されたメソッド・スタブ
354
+
355
+
356
+
357
+ try {
358
+
359
+ // 画像ファイル
360
+
361
+ File file = new File("C:/Users/naoya/Desktop/2016_10_12/IMG_7863.jpg");
362
+
363
+
364
+
365
+ // 色んなデータを出力してみる
366
+
367
+ viewAllData(file);
368
+
369
+ // 項目指定したデータを出力してみる
370
+
371
+ // viewSomeData(file);
372
+
373
+ // 撮影日時をDate型で出力してみる
374
+
375
+ viewDateData(file);
376
+
377
+ } catch (Exception e) {
378
+
379
+ e.printStackTrace();
380
+
381
+ }
382
+
383
+ }
384
+
385
+
386
+
387
+ @SuppressWarnings("unchecked")
388
+
389
+ public static void viewAllData(File file) throws JpegProcessingException {
390
+
391
+ Metadata metadata = null;
392
+
393
+ try {
394
+
395
+ metadata = JpegMetadataReader.readMetadata(file);
396
+
397
+ } catch (IOException e) {
398
+
399
+ // TODO 自動生成された catch ブロック
400
+
401
+ e.printStackTrace();
402
+
403
+ }
404
+
405
+ Iterator<Directory> directories = metadata.getDirectories().iterator();
406
+
407
+ while (directories.hasNext()) {
408
+
409
+ Directory directory = directories.next();
410
+
411
+ Iterator<Tag> tags = directory.getTags().iterator();
412
+
413
+ while (tags.hasNext()) {
414
+
415
+ Tag tag = tags.next();
416
+
417
+ System.out.println(tag);
418
+
419
+ }
420
+
421
+ }
422
+
423
+ }
424
+
425
+
426
+
427
+ public static void viewSomeData(File file) throws JpegProcessingException {
428
+
429
+ Directory directory = null;
430
+
431
+ try {
432
+
433
+ directory = JpegMetadataReader.readMetadata(file).getFirstDirectoryOfType(ExifSubIFDDirectory.class);
434
+
435
+ } catch (IOException e) {
436
+
437
+ // TODO 自動生成された catch ブロック
438
+
439
+ e.printStackTrace();
440
+
441
+ }
442
+
443
+ // 装置の製造元
444
+
445
+ System.out.println(directory.getString(ExifSubIFDDirectory.TAG_MAKE));
446
+
447
+ // カメラのモデル
448
+
449
+ System.out.println(directory.getString(ExifSubIFDDirectory.TAG_MODEL));
450
+
451
+ // 写真の撮影日
452
+
453
+ System.out.println(directory.getString(ExifSubIFDDirectory.TAG_DATETIME));
454
+
455
+ }
456
+
457
+
458
+
459
+ public static void viewDateData(File file) throws JpegProcessingException, MetadataException {
460
+
461
+ Metadata metadata = null;
462
+
463
+ try {
464
+
465
+ metadata = JpegMetadataReader.readMetadata(file);
466
+
467
+ ExifSubIFDDirectory subIf = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
468
+
469
+ Date date = subIf.getDateOriginal();
470
+
471
+ System.out.println(date.toString());
472
+
473
+ } catch (IOException e) {
474
+
475
+ // TODO 自動生成された catch ブロック
476
+
477
+ e.printStackTrace();
478
+
479
+ }
480
+
481
+ }
482
+
483
+ }
484
+
485
+
486
+
487
+ ```

1

つづりが間違っていたため、修正

2018/05/02 06:00

投稿

sobue
sobue

スコア329

test CHANGED
File without changes
test CHANGED
@@ -78,7 +78,7 @@
78
78
 
79
79
  try {
80
80
 
81
- directory = JpegMetadataReader.readMetadata(file).getDirectry(ExifDirectory.class);
81
+ directory = JpegMetadataReader.readMetadata(file).getDirectory(ExifDirectory.class);
82
82
 
83
83
  } catch (IOException e) {
84
84