LoginSignup
2
0

More than 5 years have passed since last update.

sanselanを使ったExif情報の削除

Last updated at Posted at 2017-11-14

Java/AndroidでExifを削除する時にsanselanという便利なライブラリを使わせて頂きました。
このライブラリを使った理由は、metadata-extractorは読み取り専用なのでExif情報の削除や追加・修正が出来ないこと、ExifInterfaceは挙動が不安定なため使えなかったからです。

使い方

/* import省略 */

public static void Main(String[] args) {

    String path1 = "c:\image\img0001.jpg";   // ファイルパス
    String path2 = path.toLowerCase().replace(".jpg", "_clr_exif.jpg");

    // Exif情報の削除
    removeExifTag(new File(path1), new File(path2));
}

public static void removeExifTag(final File srcJpegFile, final File dstJpegFile) {

    OutputStream os = null;

    try {
        os = new FileOutputStream(dstJpegFile);
        os = new BufferedOutputStream(os);

        // Exif削除メソッド
        new ExifRewriter().removeExifMetadata(srcJpegFile, os);

        os.close();
        os = null;

        System.out.println("SUCCESS");
    } catch (FileNotFoundException e) {
        System.out.println("ERROR");
        e.printStackTrace();
    } catch (ImageWriteException e) {
        System.out.println("ERROR1");
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("ERROR2");
        e.printStackTrace();
    } catch (ImageReadException e) {
        e.printStackTrace();
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (final IOException e) {

            }
        }
    }
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0