Writing XPKeywords in Exif

守給你的承諾、 提交于 2019-12-30 07:56:14

问题


I want to write XPKeywords in a Jpeg Image. Till now I am using Sansaleen java api for writing Exif tags in Jpeg images. I am able to write most of the tags like subject, comment, author, rating but I am not able to write Windows XP Keywords. I am using below code:

public static TiffOutputField getTiffOutputFieldKeyword(
        TiffOutputSet outputSet, String metaDataToChange) {
    TiffOutputField imageHistoryPre = outputSet
            .findField(TiffConstants.EXIF_TAG_XPKEYWORDS);
    if (imageHistoryPre != null) {
        outputSet.removeField(TiffConstants.EXIF_TAG_XPKEYWORDS);
    }

    TiffOutputField tiffOutputField = new TiffOutputField(
            TiffConstants.EXIF_TAG_XPKEYWORDS,
            TiffFieldTypeConstants.FIELD_TYPE_BYTE,
            metaDataToChange.length(), metaDataToChange.getBytes("UTF-16"));

    return tiffOutputField;
}

I have googled this issue and came to know that XP_Keyword accept special encoded in UCS2 so I have updated my code. But still not able to write complete tags. Tags are semi-colon separated.

Please let me know if there present any resolution for the above issue or is there any other java/android lib which can write Tags in Jpeg files.


回答1:


Got it working:

public static TiffOutputField getTiffOutputFieldKeyword(
    TiffOutputSet outputSet, String metaDataToChange) {
TiffOutputField imageHistoryPre = outputSet
        .findField(TiffConstants.EXIF_TAG_XPKEYWORDS);
if (imageHistoryPre != null) {
    outputSet.removeField(TiffConstants.EXIF_TAG_XPKEYWORDS);
}

TiffOutputField tiffOutputField = new TiffOutputField(
        TiffConstants.EXIF_TAG_XPKEYWORDS,
        TiffFieldTypeConstants.FIELD_TYPE_BYTE,
        metaDataToChange.getBytes("UTF-16").length, metaDataToChange.getBytes("UTF-16"));

return tiffOutputField;
}

Just use length of Bytes in "UTF-16" and then write. Also, Make sure you trim the characters to not include any spaces. Also, please give a try by separating string with Semicolon(;) as By default Windows take semicolon separated keywords.



来源:https://stackoverflow.com/questions/25603990/writing-xpkeywords-in-exif

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!