Package org.apache.batik.ext.awt.image.codec

Examples of org.apache.batik.ext.awt.image.codec.PNGImageEncoder


     * @throws IOException in case of an I/O problem
     */
    public static void saveAsPNG(BufferedImage bitmap, File outputFile) throws IOException {
        OutputStream out = new FileOutputStream(outputFile);
        try {
            PNGImageEncoder encoder = new PNGImageEncoder(
                    out,
                    PNGEncodeParam.getDefaultEncodeParam(bitmap));
            encoder.encode(bitmap);
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
View Full Code Here


   */
  public void savePNGWithBatik(String filename, BufferedImage image) {
    File outfile = new File(filename);
    OutputStream fos = createFile(outfile);
    PNGEncodeParam param = PNGEncodeParam.getDefaultEncodeParam(image);
    PNGImageEncoder encoder = new PNGImageEncoder(fos, param);
    try {
      encoder.encode(image);
    } catch (Exception e) {
      // do nothing
    } finally {
      JOrphanUtils.closeQuietly(fos);
    }
View Full Code Here

   */
  public void savePNGWithBatik(String filename, BufferedImage image) {
    File outfile = new File(filename);
    OutputStream fos = createFile(outfile);
    PNGEncodeParam param = PNGEncodeParam.getDefaultEncodeParam(image);
    PNGImageEncoder encoder = new PNGImageEncoder(fos, param);
    try {
      encoder.encode(image);
    } catch (Exception e) {
      // do nothing
    } finally {
      JOrphanUtils.closeQuietly(fos);
    }
View Full Code Here

    {

        BufferedImage bufferedImage;
        Graphics2D graphics;
        PNGEncodeParam param;
        PNGImageEncoder captchaPNGImage;

        // Create the CAPTCHA Image.
        bufferedImage = new BufferedImage(
                CAPTCHAConstants.DEFAULT_CAPTCHA_WIDTH,
                CAPTCHAConstants.DEFAULT_CAPTCHA_HEIGHT,
                BufferedImage.TYPE_BYTE_INDEXED);

        // Setup the graphics object.
        graphics = bufferedImage.createGraphics();

        applyCurrentGradientPaint(graphics, bufferedImage.getWidth(),
                bufferedImage.getHeight(), startingColor, endingColor);

        graphics.fillRect(0, 0, bufferedImage.getWidth(), bufferedImage
                .getHeight());

        graphics.setColor(Color.black);

        // Draw text on the CAPTCHA image.
        drawTextOnImage(graphics, captchaText);

        // Apply noise on the CAPTCHA image.
        applyNoiseOnImage(graphics, bufferedImage.getWidth(), bufferedImage
                .getHeight(), startingColor, endingColor);

        // Draw the image border.
        drawBorders(graphics, bufferedImage.getWidth(), bufferedImage
                .getHeight());

        // Set the reponse content type to jpeg.
        response.setContentType("image/jpg");

        param = PNGEncodeParam.getDefaultEncodeParam(bufferedImage);
        captchaPNGImage = new PNGImageEncoder(response.getOutputStream(), param);

        captchaPNGImage.encode(bufferedImage);
    }
View Full Code Here

     * @throws IOException in case of an I/O problem
     */
    public static void saveAsPNG(BufferedImage bitmap, File outputFile) throws IOException {
        OutputStream out = new FileOutputStream(outputFile);
        try {
            PNGImageEncoder encoder = new PNGImageEncoder(
                    out,
                    PNGEncodeParam.getDefaultEncodeParam(bitmap));
            encoder.encode(bitmap);
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
View Full Code Here

    {

        BufferedImage bufferedImage;
        Graphics2D graphics;
        PNGEncodeParam param;
        PNGImageEncoder captchaPNGImage;

        // Create the CAPTCHA Image.
        bufferedImage = new BufferedImage(
                CAPTCHAConstants.DEFAULT_CAPTCHA_WIDTH,
                CAPTCHAConstants.DEFAULT_CAPTCHA_HEIGHT,
                BufferedImage.TYPE_BYTE_INDEXED);

        // Setup the graphics object.
        graphics = bufferedImage.createGraphics();

        applyCurrentGradientPaint(graphics, bufferedImage.getWidth(),
                bufferedImage.getHeight(), startingColor, endingColor);

        graphics.fillRect(0, 0, bufferedImage.getWidth(), bufferedImage
                .getHeight());

        graphics.setColor(Color.black);

        // Draw text on the CAPTCHA image.
        drawTextOnImage(graphics, captchaText);

        // Apply noise on the CAPTCHA image.
        applyNoiseOnImage(graphics, bufferedImage.getWidth(), bufferedImage
                .getHeight(), startingColor, endingColor);

        // Draw the image border.
        drawBorders(graphics, bufferedImage.getWidth(), bufferedImage
                .getHeight());

        param = PNGEncodeParam.getDefaultEncodeParam(bufferedImage);
        captchaPNGImage = new PNGImageEncoder(out, param);

        captchaPNGImage.encode(bufferedImage);
    }
View Full Code Here

        // num Pixs in 1 Meter
        int numPix      = (int)((1000/PixSzMM)+0.5);
        params.setPhysicalDimension(numPix, numPix, 1); // 1 means 'pix/meter'

        try {
            PNGImageEncoder pngEncoder = new PNGImageEncoder(ostream, params);
            pngEncoder.encode(img);
            ostream.close();
        } catch (IOException ex) {
            throw new TranscoderException(ex);
        }
    }
View Full Code Here

                            (b     & 0xff);
             }
            p += adjust;
        }
        try {
            PNGImageEncoder pngEncoder = new PNGImageEncoder(ostream, params);
            pngEncoder.encode(img);
        } catch (IOException ex) {
            throw new TranscoderException(ex);
        }
    }
View Full Code Here

    }

    public void encodeImage(RenderedImage buf, OutputStream os)
        throws SVGGraphics2DIOException {
        try{
            ImageEncoder encoder = new PNGImageEncoder(os, null);
            encoder.encode(buf);
        } catch(IOException e) {
            // We are doing in-memory processing. This should not happen.
            throw new SVGGraphics2DIOException(ERR_UNEXPECTED);
        }
    }
View Full Code Here

     */
    public void encodeImage(BufferedImage buf, File imageFile)
        throws SVGGraphics2DIOException {
        try {
            OutputStream os = new FileOutputStream(imageFile);
            ImageEncoder encoder = new PNGImageEncoder(os, null);
            encoder.encode(buf);
            os.close();
        } catch (IOException e) {
            throw new SVGGraphics2DIOException(ERR_WRITE+imageFile.getName());
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.batik.ext.awt.image.codec.PNGImageEncoder

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.