如何将图像元数据读入文本文件

时间:2016-03-29 14:25:48

标签: image metadata exif

我正在使用org.apache.commons.imaging来访问jpeg文件的元数据并将其写入文本文件。但是,程序不是将元数据写入文件,而是将随机字符写入文本文件。有人可以帮我解决这个问题吗?以下是代码

    //Method to access image metadata and write to text file
    public void removeExifMetadata(final File jpegImageFile, final File dst)
        throws IOException, ImageReadException, ImageWriteException {
    OutputStream os = null;
    boolean canThrow = false;
    try {
        os = new FileOutputStream(dst);
        os = new BufferedOutputStream(os);

        new ExifRewriter().removeExifMetadata(jpegImageFile, os);
        canThrow = true;
    } finally {
        IoUtils.closeQuietly(canThrow, os);
         File metadata=new File("matadata.txt");
         if(!metadata.exists()){
             metadata.createNewFile();
         }
         System.out.printf("in try block\n");
        FileOutputStream fos = new FileOutputStream(metadata);
        TeeOutputStream myOut=new TeeOutputStream(System.out, fos);
         PrintStream ps = new PrintStream(myOut);
         System.setOut(ps);
         System.out.printf("in final block\n");
    }
}
//call to removeExifMetadata from main

    File imageFile=new File("toddler.jpg");
        File out=new File("exif.txt");
        e.removeExifMetadata(imageFile, out);

0 个答案:

没有答案