原來就足夠了包括EXIF標籤的ColorSpace = 1,告訴它應該爲sRGB進行處理。使用Apache Commons Sanselan成功完成此操作。這個庫不幸的是不完整的,因此只能用在文件被創建後修改EXIF。
相關代碼,基於Sanselan例如:
public void addExifMetadata(File jpegImageFile, File dst)
throws IOException, ImageReadException, ImageWriteException {
OutputStream os = null;
try {
TiffOutputSet outputSet = new TiffOutputSet();
TiffOutputField colorspace = TiffOutputField.create(
TiffConstants.EXIF_TAG_COLOR_SPACE, outputSet.byteOrder, new Integer(1));
TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory();
exifDirectory.add(colorspace);
os = new FileOutputStream(dst);
os = new BufferedOutputStream(os);
new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os, outputSet);
os.close();
os = null;
} finally {
if (os != null)
try {
os.close();
} catch (IOException e) {
}
}
}