[JAVA] Deleting Exif information using sanselan

I used a convenient library called sanselan when deleting Exif in Java / Android. The reason for using this library is that metadata-extractor is read-only, so Exif information cannot be deleted, added, or modified, and Exif Interface cannot be used due to its unstable behavior.

How to use

/*import omitted*/

public static void Main(String[] args) {

    String path1 = "c:\image\img0001.jpg ";   //File Path
    String path2 = path.toLowerCase().replace(".jpg ", "_clr_exif.jpg ");

    //Delete Exif information
    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 delete method
        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) {

            }
        }
    }
}

Recommended Posts

Deleting Exif information using sanselan
Get EXIF information in Java
Read JPEG Exif information ~ metadata-extractor ~
[Hidden_field] Let's send information using rails hidden_field !!!!
Acquisition of location information using FusedLocationProviderClient
Deleting files using recursive processing [Java]