我们正在尝试删除png图像的Exif,IPTC和XMP数据 . 请提供相同的示例代码
-
我们有一个png图像文件 .
-
需要删除Exif,IPTC和XMP数据 .
package com.test;
import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream;
import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; import org.apache.commons.imaging.formats.jpeg.iptc.JpegIptcRewriter;
class ImageUploadTest {
public static void main(String[] args) {
try {
final File original = new File(
"/Users/anupam256093/Downloads/Test.png");
final File newimage = new File(
"/Users/anupam256093/Downloads/Test_resized2.png");
removeExifTag(original, newimage);
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e);
}
}
public static void removeExifTag(final File jpegImageFile, final File dst) {
OutputStream os = null;
OutputStream osiptc = null;
try {
System.out.println("4");
os = new FileOutputStream(dst);
os = new BufferedOutputStream(os);
System.out.println("15");
osiptc = new FileOutputStream(dst);
osiptc = new BufferedOutputStream(osiptc);
new JpegIptcRewriter().removeIPTC(jpegImageFile, os);
// new ExifRewriter().removeExifMetadata(jpegImageFile, os);
System.out.println("15");
//new PngWriter(true).writeImage(jpegImageFile, os, null);
//System.out.println("16");
os.close();
os = null;
System.out.println("7");
System.out.println("SUCCESS");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("ERROR");
e.printStackTrace();
} catch (ImageWriteException e) {
// TODO Auto-generated catch block
System.out.println("ERROR1");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("ERROR2");
e.printStackTrace();
} catch (ImageReadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (os != null) {
try {
os.close();
} catch (final IOException e) {
}
}
}
}
}
我们正在尝试删除png图像的Exif,IPTC和XMP数据 . 请提供相同的示例代码
-
我们有一个png图像文件 .
-
需要删除Exif,IPTC和XMP数据 .
1 回答