Package com.sun.media.jai.codec

Examples of com.sun.media.jai.codec.ImageEncoder


     * -------------------------------- alle Bilder als Multipage erzeugen --------------------------------
     */
    OutputStream out = new FileOutputStream(this.help.getGoobiDataDirectory() + inProzess.getId().intValue() + File.separator + "multipage.tiff");
    TIFFEncodeParam param = new TIFFEncodeParam();
    param.setCompression(4);
    ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF", out, param);
    Vector<RenderedImage> vector = new Vector<RenderedImage>();
    for (int i = 1; i < image.length; i++) {
      vector.add(image[i]);
    }
    param.setExtraImages(vector.iterator());
    encoder.encode(image[0]);
    out.close();
    myLogger.debug("fertig");
  }
View Full Code Here


                } catch (FileNotFoundException ex) {
                    throw new IllegalActionException(this, ex,
                            "Could not create stream '" + fileRoot + "'");
                }

                ImageEncoder encoder = ImageCodec.createImageEncoder(
                        _imageEncoderName, stream, _imageEncodeParam);

                if (encoder == null) {
                    throw new IllegalActionException(this,
                            "Could not create encoder for \""
                                    + _imageEncoderName + "\", to \""
                                    + fileRoot
                                    + "\". Perhaps the encoder name is wrong?"
                                    + "encoder was: " + _imageEncodeParam);
                }

                try {
                    encoder.encode(_image);
                } catch (IOException ex) {
                    throw new IllegalActionException(this, ex,
                            "Couldn't encode image");
                }
            } finally {
View Full Code Here

            }

            PlanarImage thumbImage = new RenderedImageAdapter( ri.getRenderedImage( 200, 200, true ) );

            JPEGEncodeParam encodeParam = new JPEGEncodeParam();
            ImageEncoder encoder = ImageCodec.createImageEncoder("JPEG", os,
                    encodeParam);
            try {
                encoder.encode( thumbImage );
                os.close();
                // origImage.dispose();
                thumbImage.dispose();
            } catch (Exception e) {
                fail( "Error writing thumbnail: " + e.getMessage() );
View Full Code Here

    private void writeImage(RenderedImage image, OutputStream os, MimeType mime) throws IOException {
        if ("image/png".equals(mime.getName())) {
            JAI.create("encode", image, os, "PNG", null);
        } else {
            JPEGEncodeParam params = new JPEGEncodeParam();
            ImageEncoder encoder = ImageCodec.createImageEncoder("JPEG", os, params);
            encoder.encode(image);
        }
    }
View Full Code Here

    RenderedImage oRenderedImg;
    PlanarImage oPlI;
    RenderedOp oScI;
    ParameterBlock oBlk;
    ImageEncoder oImgEnc;
    ImageDecoder oDecoder;

    Log.out.debug("Begin Picture.drawJAIImage("+sCodec+","+String.valueOf(iThumbWidth)+","+String.valueOf(iThumbHeight)+")");
   
    oDecoder = com.sun.media.jai.codec.ImageCodec.createImageDecoder(sCodec, imgSrc, null);

    oRenderedImg = oDecoder.decodeAsRenderedImage();

    if (sCodec.equals("gif")) {
      // Increase color depth to 16M RGB
      try {
        javax.media.jai.ImageLayout layout = new javax.media.jai.ImageLayout();

        ColorModel cm = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                                 new int[] {8,8,8}, false, false,
                                                 Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
        layout.setColorModel(cm);
        layout.setSampleModel(cm.createCompatibleSampleModel(oRenderedImg.getWidth(),oRenderedImg.getHeight()));
        RenderingHints hints = new RenderingHints(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, layout);
        ParameterBlockJAI pb = new ParameterBlockJAI( "format" );
        pb.addSource( oRenderedImg );
        oRenderedImg = javax.media.jai.JAI.create( "format", pb, hints );
      } catch (IllegalArgumentException iae) {
      }
      // End increase color depth
    } // gif

    oPlI = PlanarImage.wrapRenderedImage(oRenderedImg);

    int iImageWidth = oPlI.getWidth();
    int iImageHeight = oPlI.getHeight();

    float thumbRatio = ((float) iThumbWidth) / ((float) iThumbHeight);

    float imageRatio = ((float) iImageWidth) / ((float) iImageHeight);

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

    float scaleW = ((float) iThumbWidth) / ((float) iImageWidth);

    float scaleH = ((float) iThumbHeight) / ((float) iImageHeight);

    oBlk = new ParameterBlock();

    oBlk.addSource(oPlI);

    oBlk.add(scaleW);
    oBlk.add(scaleH);
    oBlk.add(0.0f);
    oBlk.add(0.0f);
    oBlk.add(new javax.media.jai.InterpolationBilinear());

    oScI = JAI.create("scale", oBlk, null); // scale image NOW !
       
    oImgEnc = ImageCodec.createImageEncoder( "jpeg", outStr, null );
    if (null==oImgEnc) {
      throw new NullPointerException("Cannot create ImageEncoder for jpeg");
    }
    else {
      oImgEnc.encode( oScI ); // write encoded data to given output stream
      oImgEnc =null;
    }

    Log.out.debug("End Picture.drawJAIImage()");

View Full Code Here

    if (null==oImg) {
      throw new NullPointerException("java.awt.Image is null");
    }

    ImageEncoder oEnc = ImageCodec.createImageEncoder(sCodec, oOut, null);

    if (null==oEnc) {

      throw new InstantiationException("ImageCodec.createImageEncoder("+sCodec+")");
    }
    if (USE_JAI==iImagingLibrary) {

      RenderedImage oRImg = javax.media.jai.JAI.create("awtimage", oImg);

      if (null==oEnc) {
        throw new InstantiationException("JAI.create(awtimage, "+oImg.getClass().getName()+")");
      }

      oEnc.encode(oRImg);
    }
    else {
      int iImageWidth = oImg.getWidth(null);
      int iImageHeight = oImg.getHeight(null);

      if (null==mediaTracker) {

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

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

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

      BufferedImage oBImg = new BufferedImage(iImageWidth, iImageHeight, BufferedImage.TYPE_INT_RGB);

      Graphics2D graphics2D = oBImg.createGraphics();
      graphics2D.drawImage(oImg, 0, 0, iImageWidth, iImageHeight, null);
      graphics2D.dispose();

      oEnc.encode(oBImg);

      mediaTracker.removeImage(oImg,0);
    }
  }
View Full Code Here

        if(paramBlock.getNumParameters() > 2) {
            param = (ImageEncodeParam)paramBlock.getObjectParameter(2);
        }

        // Create an ImageEncoder.
        ImageEncoder encoder =
            ImageCodec.createImageEncoder(format, stream, param);

        // Check the ImageEncoder.
        if(encoder == null) {
            throw new RuntimeException(JaiI18N.getString("EncodeRIF0"));
        }

        // Store the data.
        RenderedImage im = (RenderedImage)paramBlock.getSource(0);
        try {
            encoder.encode(im);
            stream.flush();
      // Fix 4665208: EncodeRIF closed the stream after flush
      // User may put more into the stream
            //stream.close();
        } catch (IOException e) {
View Full Code Here

      BufferedOutputStream bos = null;
      try {
        bos = new BufferedOutputStream(os);
        PNMEncodeParam param = new PNMEncodeParam();
        param.setRaw(true);
        ImageEncoder enc = ImageCodec.createImageEncoder("PNM", bos, param);
        enc.encode(bi);
      } catch (IOException e) {
        logger.error(e,e);
      }
    }
  }
View Full Code Here

  public void write(BufferedImage bi, OutputStream os) throws FormatIOException {
    if (bi != null) {
      BufferedOutputStream bos = null;
      try {
        bos = new BufferedOutputStream(os);
        ImageEncoder enc = ImageCodec.createImageEncoder("BMP", bos, param);
        enc.encode(bi);
      } catch (IOException e) {
        logger.error(e,e);
      }
    }
  }
View Full Code Here

/* 62 */     ImageEncodeParam param = null;
/* 63 */     if (paramBlock.getNumParameters() > 2) {
/* 64 */       param = (ImageEncodeParam)paramBlock.getObjectParameter(2);
/*    */     }
/*    */
/* 68 */     ImageEncoder encoder = ImageCodec.createImageEncoder(format, stream, param);
/*    */
/* 72 */     if (encoder == null) {
/* 73 */       throw new RuntimeException(JaiI18N.getString("EncodeRIF0"));
/*    */     }
/*    */
/* 77 */     RenderedImage im = (RenderedImage)paramBlock.getSource(0);
/*    */     try {
/* 79 */       encoder.encode(im);
/* 80 */       stream.flush();
/*    */     }
/*    */     catch (IOException e)
/*    */     {
/* 85 */       String message = JaiI18N.getString("EncodeRIF1") + " " + format;
View Full Code Here

TOP

Related Classes of com.sun.media.jai.codec.ImageEncoder

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.