java ImageIO API PNG image

Discussion in 'Software' started by nekt, Feb 11, 2009.

  1. nekt

    nekt

    Joined:
    Feb 11, 2009
    Messages:
    1
    Hello people

    I need your help for program related to ImageIO API while working on PNG images.


    Here is the code,

    import java.io.*;
    import java.util.*;
    import java.awt.image.*;
    import javax.imageio.*;
    import javax.imageio.stream.ImageOutputStream;
    import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
    import com.sun.media.imageioimpl.plugins.png.*; // had to comment this as this package does not exist
    //import com.sun.imageio.plugins.png;

    public class TestWriter
    {
    public static void main(String[] args)
    throws IOException
    {
    /*
    if (args.length < 2) {
    // Exit if both the arguments (Input File and Output File) are not provided
    System.err.println("Usage: java TestWriter c:\\in.png c:\\out.png");
    return;
    }
    */
    Iterator writers;
    BufferedImage bufferedImage;
    ImageOutputStream imageOutputStream;
    ImageWriter imageWriter;
    ImageWriteParam pngparams;

    // Read an image from the disk (First Argument)
    //bufferedImage = ImageIO.read(new File(args[0]));
    bufferedImage = ImageIO.read(new File("Download.png"));
    // Get all the PNG writers
    writers = ImageIO.getImageWritersByFormatName( "png" );

    // Fetch the first writer in the list
    imageWriter = (ImageWriter) writers.next();

    // Just to confirm that the writer in use is CLibPNGImageWriter
    System.out.println("\n Writer used : " + imageWriter.getClass().getName() + "\n");

    // Specify the parameters according to those the output file will be written

    // Get Default parameters
    pngparams = imageWriter.getDefaultWriteParam();

    // Define compression mode
    pngparams.setCompressionMode( javax.imageio.ImageWriteParam.MODE_EXPLICIT );

    // Define compression quality
    pngparams.setCompressionQuality( 0.5F );

    // Define progressive mode
    pngparams.setProgressiveMode( javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA );

    // Deine destination type - used the ColorModel and SampleModel of the Input Image
    pngparams.setDestinationType(
    new ImageTypeSpecifier( bufferedImage.getColorModel(), bufferedImage.getSampleModel() ) );

    // Set the output stream to Second Argument
    //imageOutputStream = ImageIO.createImageOutputStream( new FileOutputStream(args[1]) );
    imageOutputStream = ImageIO.createImageOutputStream( new FileOutputStream("PNGCopy.png") );
    imageWriter.setOutput( imageOutputStream );

    // Write the changed Image
    imageWriter.write( null, new IIOImage( bufferedImage, null, null ), pngparams );

    // Close the streams
    imageOutputStream.close();
    imageWriter.dispose();
    }
    }




    And, I get the following exception, package com.sun.media.imageioimpl.plugins.png does not exist



    Please guide me if I need to add specific JARs to use this code involving PNG images.





    Thanks


    Nek
     
    nekt, Feb 11, 2009
    #1
    1. Advertising

  2. nekt

    susith

    Joined:
    Feb 25, 2009
    Messages:
    16
    refer
    www . exampledepot . com/egs/javax.imageio/pkg.html
     
    susith, Feb 27, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. goonmunster
    Replies:
    1
    Views:
    1,034
    Moz Champion
    Feb 12, 2005
  2. goonmunster
    Replies:
    0
    Views:
    490
    goonmunster
    Feb 11, 2005
  3. Rili

    IrfanView versus XnView for PNG files

    Rili, Oct 25, 2003, in forum: Digital Photography
    Replies:
    3
    Views:
    851
  4. =?Utf-8?B?TGVv?=
    Replies:
    0
    Views:
    652
    =?Utf-8?B?TGVv?=
    Sep 5, 2007
  5. Del Cotter

    Re: PNG Picture Frame image

    Del Cotter, Apr 15, 2008, in forum: Digital Photography
    Replies:
    1
    Views:
    2,403
    glennrp@gmail.com
    Apr 16, 2008
Loading...

Share This Page