问题
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.
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.
Convert from: FF D8 FF E1 Exif
to FF D8 FF E0 JFIF
回答1:
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.
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.
You can read more about the JFIF standard here: http://www.w3.org/Graphics/JPEG/jfif3.pdf
来源:https://stackoverflow.com/questions/7676701/java-jpeg-converter-for-odd-image-types