用于奇数图像类型的Java JPEG转换器 [英] Java JPEG Converter for Odd Image Types

查看:89
本文介绍了用于奇数图像类型的Java JPEG转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,使用mortennobel图像库重新缩放图像,用于重新缩放滤镜/算法。我正在使用Java标准库ImageIO将文件读入 BufferedImage 对象。但是我遇到的麻烦是ImageIO库只接受标准形式的图像,所以如果 ImageIO.read()函数抛出 IOException 我想抓住它并将图像转换为标准格式,如JPEG。

I have a program which rescales images using the mortennobel image library for the rescale filter/algorithm. I'm using the Java standard library ImageIO to read the file into a BufferedImage object. However the trouble I'm having is that the ImageIO library only accepts standard forms of images and so if the ImageIO.read() function throws an IOException I want to catch it and convert the image into a standard form such as a JPEG.

为了澄清,我遇到的问题是某些图像不是标准的JPEG格式,即 FF D8 FF E0 JFIF ,相反,它们是由数码相机制作或在photoshop中编辑的,格式为 FF D8 FF E1 Exif 。可以通过将图像加载到像paint这样的程序并再次保存为JPEG来改变这种格式,但它不适合我的情况,因为我希望它是自动化的。

Just to clarify, the problem I'm having is that some of the images are not of a standard JPEG format i.e. FF D8 FF E0 JFIF, instead they have been produced by a digital camera or edited in photoshop and the format is FF D8 FF E1 Exif. It's possible to change this format by loading the image into a program like paint and saving again as JPEG however its not ideal for my situation as I'd like it to be automated.

转换自: FF D8 FF E1 Exif FF D8 FF E0 JFIF

推荐答案

FFE0标记后的第一个字段是长度字段。它是16位长的大端,包括长度字段的长度,但不包括FFE0标记。只需复制FFE0标记和现有jpeg中的相关数据,并将其放入FFD8和FFE1之间。

The first field after FFE0 marker is the length field. It's 16 bits long big endian and includes the length of the length field but not the FFE0 marker. Just copy the FFE0 marker and the associated data from an existing jpeg and fit it in between FFD8 and FFE1.

根据JFIF标准,JFIF标题应立即跟随SOI(FFD8)。没有JFIF标头的每个jpeg基本上都被破坏了,因为无法知道使用什么颜色编码。当然有Adobe jpeg,但它们并不算数。如果有JFIF标题,您就知道图像是在YCbCr中编码的。如果没有JFIF标题,你可能会认为它是YCbCr,但你无法确定。

According to the JFIF standard, the JFIF header should follow immediately after SOI (FFD8). Every jpeg without a JFIF header is essentially broken as there's no way of knowing what color coding is used. Of course there's the Adobe jpeg's but they don't really count. If there's a JFIF header, you know that the image is coded in YCbCr. If there's no JFIF header, you could maybe assume it's YCbCr, but you can't know for sure.

你可以在这里阅读更多关于JFIF标准: http://www.w3.org/Graphics/JPEG/jfif3.pdf

You can read more about the JFIF standard here: http://www.w3.org/Graphics/JPEG/jfif3.pdf

这篇关于用于奇数图像类型的Java JPEG转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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