如何填充 windows exif 标签

how to fill windows exif tags

晚上好 我要填写jpg图片文件windows属性

显然这些是 exiftags

[Exif IFD0] Windows XP Title
[Exif IFD0] Windows XP Author
[Exif IFD0] Windows XP Subject

我查看了icafe.jar的侧面,但没有找到这些标签。 我可以用 icafe 或其他 jar 库制作它吗?

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import com.icafe4j.image.meta.Metadata;
import com.icafe4j.image.meta.exif.Exif;
import com.icafe4j.image.meta.jpeg.JpegExif;
import com.icafe4j.image.meta.exif.ExifTag;
import com.icafe4j.image.tiff.TiffTag;
import com.icafe4j.image.tiff.FieldType;

fin = new FileInputStream(Fm_filePathIn);
fout = new FileOutputStream(Fm_filePathOut);


List<Metadata> metaList = new ArrayList<Metadata>();
 metaList.add(populateExif(JpegExif.class));

Exif populateExif(Class<?> exifClass) throws IOException {

Exif exif = new JpegExif();

    exif.addImageField(ExifTag.WINDOWS_XP_AUTHOR, FieldType.WINDOWSXP, "Toto");
    exif.addImageField(ExifTag.WINDOWS_XP_KEYWORDS, FieldType.WINDOWSXP, "Copyright;Authorbisou");
// Insert ThumbNailIFD
    // Since we don't provide thumbnail image, it will be created later from the input stream
    exif.setThumbnailRequired(true);

    return exif;
  }


        fin.close();
        fout.close();

ICAFE 中确实存在这些标签,但它们不是 Exiftag。他们是 TiffTag。用 TiffTag 替换 ExifTag,它将起作用。看TestMetada.java,很明显。

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.icafe4j.image.meta.Metadata;
import com.icafe4j.image.meta.exif.Exif;
import com.icafe4j.image.meta.jpeg.JpegExif;
import com.icafe4j.image.meta.exif.ExifTag;
import com.icafe4j.image.tiff.TiffTag;
import com.icafe4j.image.tiff.FieldType;

public class TestWindowsXP {

 public static void main(String[] args) throws IOException {

    FileInputStream fin = new FileInputStream(Fm_filePathIn);
    FileOutputStream fout = new FileOutputStream(Fm_filePathOut);

    List<Metadata> metaList = new ArrayList<Metadata>();

    Exif exif = new JpegExif();

    exif.addImageField(TiffTag.WINDOWS_XP_AUTHOR, FieldType.WINDOWSXP, "Toto");
    exif.addImageField(TiffTag.WINDOWS_XP_KEYWORDS, FieldType.WINDOWSXP, "Copyright;Authorbisou");
    // Insert ThumbNailIFD
    // Since we don't provide thumbnail image, it will be created later from the input stream
    exif.setThumbnailRequired(true);

    metaList.add(exif);
    Metadata.insertMetadata(metaList, fin, fout);

    fin.close();
    fout.close();
 }
}

下面是我右击生成的图像->显示属性时的截图。您可以看到您要插入的信息正在显示。