Package com.sun.image.codec.jpeg

Examples of com.sun.image.codec.jpeg.JPEGEncodeParam


    // send thumbnail image to outputstream
    String sOutFile = Gadgets.generateUUID() + ".tmp";
    ServletOutputStream out = sOutputStream;
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
    int quality = Integer.parseInt(sQuality);
    quality = Math.max(0, Math.min(quality, 100));
    param.setQuality((float)quality / 100.0f, false);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(thumbImage);

    if (DebugFile.trace)
      DebugFile.writeln("Encode ended");
View Full Code Here


  private void drawAWTImage(OutputStream outStr, int iThumbWidth, int iThumbHeight, float fQuality) throws IOException, InstantiationException, InterruptedException {

    String sInputURI;
    Frame awtFrame;
    JPEGImageEncoder encoder;
    JPEGEncodeParam param;
    BufferedImage thumbImage;
    Graphics2D graphics2D;
    URL oURI;

    if (DebugFile.trace) {
      DebugFile.writeln("Begin Image.drawAWTImage([OutputStream], " + String.valueOf(iThumbWidth) + "," + String.valueOf(iThumbHeight) + "," + String.valueOf(fQuality));
      DebugFile.incIdent();
    }

    sInputURI = getString(DB.path_image);

    if (sInputURI.startsWith("http://") || sInputURI.startsWith("https://")) {
      oURI = new URL(sInputURI);

      if (DebugFile.trace) DebugFile.writeln("java.awt.Toolkit.getDefaultToolkit().getImage([java.net.URL])");

      oImg = Toolkit.getDefaultToolkit().getImage(oURI);
    }
    else {
      if (DebugFile.trace) DebugFile.writeln("java.awt.Toolkit.getDefaultToolkit().getImage(sInputURI)");

      oImg = Toolkit.getDefaultToolkit().getImage(sInputURI);
    }

    int iImageWidth = oImg.getWidth(null);
    int iImageHeight = oImg.getHeight(null);

    double thumbRatio = ((double) iThumbWidth) / ((double) iThumbHeight);
    double imageRatio = ((double) iImageWidth) / ((double) iImageHeight);

    if (thumbRatio < imageRatio)
      iImageHeight = (int)(iThumbWidth / imageRatio);
    else
      iThumbWidth = (int)(iThumbHeight * imageRatio);

    if (null==mediaTracker) {
      if (DebugFile.trace) DebugFile.writeln("new java.awt.;Frame()");

      try {
        awtFrame = new Frame();
      } catch (Exception e) { throw new InstantiationException("Cannot instantiate java.awt.Frame " + (e.getMessage()!=null ? e.getMessage() : "")); }

      if (DebugFile.trace) DebugFile.writeln("new MediaTracker([Frame])");

      mediaTracker = new MediaTracker(awtFrame);
    } // fi (mediaTracker)

    mediaTracker.addImage(oImg, 0);
    mediaTracker.waitForID(0);

    // draw original image to thumbnail image object and
    // scale it to the new size on-the-fly
    thumbImage = new BufferedImage(iThumbWidth, iThumbHeight, BufferedImage.TYPE_INT_RGB);

    if (DebugFile.trace) DebugFile.writeln("java.awt.Graphics2D = thumbImage.createGraphics()");

    graphics2D = thumbImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(oImg, 0, 0, iThumbWidth, iThumbHeight, null);
    graphics2D.dispose();

    if (DebugFile.trace) DebugFile.writeln("com.sun.image.codec.jpeg.JPEGImageEncoder = JPEGCodec.createJPEGEncoder([OutputStream]);");

    encoder = JPEGCodec.createJPEGEncoder(outStr);
    param = encoder.getDefaultJPEGEncodeParam(thumbImage);

  javax.imageio.plugins.jpeg.JPEGHuffmanTable t;
  javax.imageio.plugins.jpeg.JPEGQTable q;
 
    fQuality = Math.max(0, Math.min(fQuality, 100));
    if (fQuality>1)
      param.setQuality(fQuality / 100.0f, false);
    else
      param.setQuality(fQuality, false);

    encoder.setJPEGEncodeParam(param);

    if (DebugFile.trace) DebugFile.writeln("JPEGImageEncoder.encode([BufferedImage]);");

View Full Code Here

        Graphics2D biContext = image.createGraphics();
        biContext.drawImage(img, 0, 0, null);

       
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
      JPEGEncodeParam encpar = encoder.getDefaultJPEGEncodeParam(image);
      encpar.setQuality(ConnectionBean.imgQuality, false);
      encoder.setJPEGEncodeParam(encpar);
      encoder.encode(image);
     
      imageScreen.flush();
      image.flush();
View Full Code Here

      ByteArrayOutputStream out = new ByteArrayOutputStream();
     
      //PNGEncoder
     
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
      JPEGEncodeParam encpar = encoder.getDefaultJPEGEncodeParam(imageScreen);
      encpar.setQuality(ClientConnectionBean.imgQuality, false);
      encoder.setJPEGEncodeParam(encpar);
      encoder.encode(imageScreen);
     
      imageScreen.flush();
     
View Full Code Here

      biContext.drawImage(img, 0, 0, null);
     
      ByteArrayOutputStream out = new ByteArrayOutputStream();
     
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
      JPEGEncodeParam encpar = encoder.getDefaultJPEGEncodeParam(image);
     
      encpar.setQuality(ClientConnectionBean.imgQuality, false);
      encoder.setJPEGEncodeParam(encpar);
      encoder.encode(image);
     
      imageScreen.flush();
     
View Full Code Here

      biContext.drawImage(img, 0, 0, null);
     
      ByteArrayOutputStream out = new ByteArrayOutputStream();
     
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
      JPEGEncodeParam encpar = encoder.getDefaultJPEGEncodeParam(image);
     
      encpar.setQuality(ClientConnectionBean.imgQuality, false);
      encoder.setJPEGEncodeParam(encpar);
      encoder.encode(image);
     
      imageScreen.flush();
     
View Full Code Here

      ByteArrayOutputStream out = new ByteArrayOutputStream();
     
      //PNGEncoder
     
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
      JPEGEncodeParam encpar = encoder.getDefaultJPEGEncodeParam(imageScreen);
      encpar.setQuality(ClientConnectionBean.imgQuality, false);
      encoder.setJPEGEncodeParam(encpar);
      encoder.encode(imageScreen);
     
      imageScreen.flush();
     
View Full Code Here

            biContext.drawImage(img, 0, 0, null);
           
            ByteArrayOutputStream out = new ByteArrayOutputStream();
           
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            JPEGEncodeParam encpar = encoder.getDefaultJPEGEncodeParam(image);
            encpar.setQuality(ClientConnectionBean.imgQuality, false);
            encoder.setJPEGEncodeParam(encpar);
            encoder.encode(image);
           
            imageScreen.flush();
           
View Full Code Here

  ByteArrayOutputStream baos = new ByteArrayOutputStream() ;

  SampleModel sm = ras.getSampleModel() ;

  JPEGEncodeParam j2dEP = convertToJ2DJPEGEncodeParam(paramList, sm) ;
        ((JPEGParam)j2dEP).setWidth(ras.getWidth()) ;
  ((JPEGParam)j2dEP).setHeight(ras.getHeight()) ;

  JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos, j2dEP) ;
  encoder.encode(ras) ;
View Full Code Here

                Messages.formatMessage("jpeg.unspecifiedQuality", null)));
            quality = 1f;
        }
        try {
            JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(ostream);
            JPEGEncodeParam params = JPEGCodec.getDefaultJPEGEncodeParam(img);
            params.setQuality(quality, true);
            float PixSzMM = userAgent.getPixelUnitToMillimeter();
            int PixSzInch = (int)(25.4/PixSzMM+0.5);
            params.setDensityUnit(JPEGEncodeParam.DENSITY_UNIT_DOTS_INCH);
            params.setXDensity(PixSzInch);
            params.setYDensity(PixSzInch);
            jpegEncoder.encode(img, params);
        } catch (IOException ex) {
            throw new TranscoderException(ex);
        }
    }
View Full Code Here

TOP

Related Classes of com.sun.image.codec.jpeg.JPEGEncodeParam

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.