0

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

  1. 我们有一个 png 图像文件。
  2. 需要删除 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 数据。请提供相同的示例代码

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

1 回答 1

0
BufferedImage image = ImageIO.read(new File("input.png"));
ImageIO.write(image, "png", new File("output.png"));
于 2013-08-13T05:10:22.163 回答