【问题标题】:How to remove Exif,IPTC,XMP data of a png image in Java如何在 Java 中删除 png 图像的 Exif、IPTC、XMP 数据
【发布时间】:2013-08-13 05:00:10
【问题描述】:

我们正在尝试删除 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 数据。

【问题讨论】:

标签: java


【解决方案1】:
BufferedImage image = ImageIO.read(new File("input.png"));
ImageIO.write(image, "png", new File("output.png"));

【讨论】:

  • 不会删除新生成的图片中的Exif、IPTC和XMP数据。
  • 它将删除读取图像不需要的所有内容
  • 现在的问题是它增加了图像的大小。无论早先,我们都希望以 KB 为单位保持相同的大小。
  • 是的,我认为它会写入 png24 文件。不知道你能不能控制。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-17
  • 2013-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多