繁体   English   中英

如何在Java中删除png图像的Exif,IPTC,XMP数据

[英]How to remove Exif,IPTC,XMP data of a png image in Java

我们正在尝试删除png图片的Exif,IPTC和XMP数据。 请提供相同的示例代码

  1. 我们有一个png图像文件。
  2. 需要删除Exif,IPTC和XMP数据。

    打包com.test;

    导入java.io.BufferedOutputStream; 导入java.io.File; 导入java.io.FileNotFoundException; 导入java.io.FileOutputStream; 导入java.io.IOException; 导入java.io.OutputStream;

    导入org.apache.commons.imaging.ImageReadException; 导入org.apache.commons.imaging.ImageWriteException; 导入org.apache.commons.imaging.formats.jpeg.iptc.JpegIptcRewriter;

    类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数据。 请提供相同的示例代码

  1. 我们有一个png图像文件。
  2. 需要删除Exif,IPTC和XMP数据。
BufferedImage image = ImageIO.read(new File("input.png"));
ImageIO.write(image, "png", new File("output.png"));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM