在JPEG中保存色彩空间 [英] Saving colorspace in jpeg

查看:128
本文介绍了在JPEG中保存色彩空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Servlet,可以转换和缓存较小版本的照片.它是使用java.awt.image + javax.imageio和第三方重采样过滤器实现的.原始文件均以sRGB颜色配置文件上传.当我重新采样并再次保存它们时,它们仍然处于sRGB,但是这并未记录在保存的文件中.

I have a servlet to convert and cache smaller versions of photographs. It is implemented using java.awt.image + javax.imageio and a third party resample filter. The originals are all uploaded with an sRGB color profile. When I resample them and save them again they still are in sRGB however this is not recorded in the saved file.

如何确保此信息保存在文件中?

How can I make sure this information is saved in the file?

如果您想知道这有什么用,那么没有配置文件的图像在我的屏幕(Safari + OSX +校准的屏幕)上比具有正确的sRGB配置文件的饱和度要高得多.另外,我确定这是缺少的配置文件信息,而不是重采样算法.

In case you wondered it makes a difference, images without a profile are much more saturated on my screen (Safari + OSX + Calibrated screen) then when they have the correct sRGB profile. Also I'm sure it's the missing profile information and not the resampling algorithm.

推荐答案

结果证明,包含一个EXIF标签ColorSpace = 1足以说明它应作为sRGB处理.成功使用Apache Commons Sanselan执行此操作.不幸的是,该库尚未完成,因此只能在文件创建后用于修改EXIF.

Turns out it is enough to include an EXIF tag ColorSpace=1 that tells it should be processed as sRGB. Succeeded into doing this using Apache Commons Sanselan. This library is unfortunatly not complete so it can only be used to modify the EXIF after the file has been created.

相关代码,基于Sanselan示例:

Relevant code, based on Sanselan example:

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) {

                }
        }
    }

这篇关于在JPEG中保存色彩空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆