Reputation: 1578
I'm using apache-commons-sanselan.jar
API to remove EXIF
content from only JPEG
file.
How to remove this content from other file extensions?
Upvotes: 4
Views: 8586
Reputation: 1578
In addition to @little-child answer
code:
public static void removeExifTag(final String sourceImageFile, final File destinationImageFile) throws IOException, ImageReadException, ImageWriteException {
try (
OutputStream os = new FileOutputStream(destinationImageFile);
BufferedOutputStream bos = new BufferedOutputStream(os);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
){
BufferedImage originalImage = ImageIO.read(new File(sourceImageFile));
originalImage.flush();
ImageIO.write( originalImage,"jpg", baos );
byte[] imageInByte = baos.toByteArray();
new ExifRewriter().removeExifMetadata(imageInByte, bos);
baos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ImageReadException e) {
e.printStackTrace();
} catch (ImageWriteException e) {
e.printStackTrace();
}
}
Upvotes: -1
Reputation: 25028
BufferedImage image = ImageIO.read(new File("image.jpg"));
ImageIO.write(image, "jpg", new File("image.jpg"));
Metadata isn't read when you read an image. Just write it back. Replace jpg
with the extension you want.
Sources:
How to remove Exif,IPTC,XMP data of a png image in Java
How can I remove metadata from a JPEG image in Java?
Upvotes: 10