/** * Transcode file to JPEG. * * @param file Output filename * @param width Width * @param height Height * @param quality JPEG quality setting, between 0.0 and 1.0 * @throws IOException On write errors * @throws TranscoderException On input/parsing errors. */ public void saveAsJPEG(File file, int width, int height, double quality) throws IOException, TranscoderException { JPEGTranscoder t = new JPEGTranscoder(); t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(width)); t.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, new Float(height)); t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(quality)); transcode(file, t); }
/** * Transcode file to JPEG. * * @param file Output filename * @param width Width * @param height Height * @param quality JPEG quality setting, between 0.0 and 1.0 * @throws IOException On write errors * @throws TranscoderException On input/parsing errors. */ public void saveAsJPEG(File file, int width, int height, double quality) throws IOException, TranscoderException { JPEGTranscoder t = new JPEGTranscoder(); t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(width)); t.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, new Float(height)); t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(quality)); transcode(file, t); }
transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float( Math.max(0, Math.min(quality, 100)) / 100.0f)); transcoder.writeImage(thumb, new TranscoderOutput(output));
public PNGMessageBodyWriter implements MessageBodyWriter<MyPNG> { .... boolean isWriteable(java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, MediaType mediaType) { return mediaType.toString.equals("image/png"); } .... void writeTo(MyJPEG instance, java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, MediaType mediaType, MultivaluedMap<java.lang.String,java.lang.Object> httpHeaders, java.io.OutputStream entityStream) throws java.io.IOException, WebApplicationException { JPEGTranscoder t = new JPEGTranscoder(); t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8)); InputStream is = new ByteArrayInputStream(instance.getBytes()); TranscoderInput input = new TranscoderInput(is); TranscoderOutput output = new TranscoderOutput(entityStream); t.transcode(input, output); httpHeaders.put("Content-Disposition", ""attachment;filename=" + instance.getFilename()); // and so on.... httpHeaders.put("whatever else", "some other value"); }
JPEGTranscoder t = new JPEGTranscoder(); t.setErrorHandler(new ErrorHandlerBridge()); t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0)); t.addTranscodingHint(JPEGTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, new Float(25.4f / 300f)); transcode(t, svgGenerator, useCSS, rect, fos); } else if (option.equalsIgnoreCase("eps")) {