- From: Ichiro Furusato <ichiro.furusato@gmail.com>
- Date: Sat, 23 Mar 2013 17:42:10 +1300
- To: Norman Walsh <ndw@nwalsh.com>
- Cc: XProc Dev <xproc-dev@w3.org>
Hi,
We recently ran across this same issue in a project. The use of com.sun.image.*
in versions prior to Java 7 was deprecated, but in Java 7 finally
gone. Here's our
before and after code. Hope this is of some help...
Ichiro
------
BEFORE:
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageDecoder;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
...
private static final float MM_PER_INCH = 25.4F;
private static final float TARGET_JPEG_DPI = 96;
private static final float DEFAULT_JPEG_DPI = TARGET_JPEG_DPI * 3;
private static final float JPEG_TRANSCODE_RESOLUTION = MM_PER_INCH
/ DEFAULT_JPEG_DPI;
...
private void transcodeToJpeg( TranscoderInput input,
TranscoderOutput output )
throws TranscoderException
{
// create a JPEG transcoder
JPEGTranscoder transcoder = new JPEGTranscoder();
// set the transcoding hints
// 1 (no lossy)
transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, 1.0f);
transcoder.addTranscodingHint(JPEGTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER,
JPEG_TRANSCODE_RESOLUTION);
// save the image
transcoder.transcode(input, output);
}
private DecodedImage decodeJpeg(InputStream input) throws IOException {
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(input);
return new DecodedImage(decoder.decodeAsBufferedImage(),
DEFAULT_JPEG_DPI);
}
private void encodeJpeg(DecodedImage jpeg, OutputStream output)
throws IOException {
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
encoder.encode(jpeg.getImage());
}
AFTER:
import javax.imageio.ImageIO;
...
/*
* This replaces the earlier com.sun.image.codec.jpeg.*
* library with one supported by ImageIO.
*/
private DecodedImage decodeJpeg( InputStream input )
throws IOException
{
BufferedImage img = ImageIO.read(input);
return new DecodedImage(img, DEFAULT_JPEG_DPI);
}
/*
* This replaces the earlier com.sun.image.codec.jpeg.*
library with
* one supported by ImageIO.
*/
private void encodeJpeg( DecodedImage jpeg, OutputStream output )
throws IOException
{
if ( !ImageIO.write(jpeg.getImage(),"jpeg", output) ) {
throw new IOException( "error encoding JPEG image" );
}
}
On Sat, Mar 23, 2013 at 4:21 AM, Norman Walsh <ndw@nwalsh.com> wrote:
> Inigo Surguy <inigo.surguy@gmail.com> writes:
>> I think the problem's the com.sun classes for images - these have
>> been discouraged for a while (see
>> http://markmail.org/message/s4j7pbhie5wvf5b2) and I think they're
>> now more aggressively discouraged.
>
> Ahh...thank you.
>
>> The longer term solution is to switch to javax.imageio for image manipulation.
>
> I'll try a newer release of metadata-extractor and see if the problem just
> magically goes away. A quick skim of the source suggests it might...
>
>> I'm not sure why this isn't an issue on OS X - perhaps because the OS X Java is packaged by
>> Apple rather than by Sun.
Received on Saturday, 23 March 2013 04:42:37 UTC