BMP image compression

i am trying to compress bmp image but that is not showing any result, doing with following code. is there something missing in this

is there any other way which help to compress the bmp image

import java.awt.image.BufferedImage;

import java.awt.image.renderable.ParameterBlock;

import java.io.IOException;

import java.io.RandomAccessFile;

import javax.media.jai.JAI;

import javax.media.jai.PlanarImage;

import com.sun.media.jai.codec.BMPEncodeParam;

import com.sun.media.jai.codec.ImageCodec;

import com.sun.media.jai.codec.ImageEncoder;

import com.sun.media.jai.codec.SeekableOutputStream;

publicclass ExportImages

{

private ImageEncoder encoder =null;

publicstaticvoid main(String args[])

{

new ExportImages(args);

}

// Load the source image.

private PlanarImage loadImage(String imageName)

{

ParameterBlock pb = (new ParameterBlock()).add(imageName);

PlanarImage src1 = JAI.create("fileload", pb);

if (src1 ==null)

{

System.out.println("Error in loading image " + imageName);

System.exit(1);

}

return src1;

}

/**

* Create seek output stream for scaling

*

* @param outFile

* @return

*/

private SeekableOutputStream createSeekOutputStream(String outFile)

{

SeekableOutputStream out =null;

try

{

out =new SeekableOutputStream(new RandomAccessFile(outFile,"rws"));

}

catch (IOException e)

{

System.out.println("IOException.");

System.exit(1);

}

return out;

}

/**

*

* @param args

*/

public ExportImages(String args[])

{

String inFile ="C:/Test.bmp";

String outputFile ="C:/Modified_image.bmp";

SeekableOutputStream out2 = createSeekOutputStream(outputFile);

PlanarImage src = loadImage(inFile);

BufferedImage bi = src.getAsBufferedImage();

ParameterBlock pb =new ParameterBlock();

pb.addSource(bi);

pb.add(1.0F);

pb.add(1.0F);

PlanarImage image = JAI.create("scale", pb,null).getRendering();

BMPEncodeParam bmpParam =new BMPEncodeParam();

bmpParam.setVersion(BMPEncodeParam.VERSION_3);

// Doing compress

bmpParam.setCompressed(true);

encoder = ImageCodec.createImageEncoder("BMP", out2, bmpParam);

try

{

encoder.encode(image);

out2.close();

}

catch (IOException e)

{

System.out.println("IOException at encoding..");

System.exit(1);

}

}

}

ThnX

[4757 byte] By [Prashant_SDNa] at [2007-11-26 18:33:55]
# 1
RTFM: http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Encode.doc.htmlThe JAI BMP encoder does not support compression of BMP image files.
Rodney_McKaya at 2007-7-9 6:08:01 > top of Java-index,Security,Cryptography...
# 2
ThnX but i have one doubt because BMPEncodeParam is showing method setCompressed, visit this http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/com/sun/media/jai/codec/BMPEncodeParam.htmlis this something diffrent?
Prashant_SDNa at 2007-7-9 6:08:01 > top of Java-index,Security,Cryptography...
# 3
It was probably put there for future use.The documentation is very clear, there is no support for compressed BMP.
Rodney_McKaya at 2007-7-9 6:08:01 > top of Java-index,Security,Cryptography...
# 4
If you want a smaller file size, you can use the PNG format.
Lord_Jirachia at 2007-7-9 6:08:01 > top of Java-index,Security,Cryptography...
# 5
Actually I am also saving the image in PNG form but along with i also have to save in BMP format and have to compress the image.Any other idea.
Prashant_SDNa at 2007-7-9 6:08:01 > top of Java-index,Security,Cryptography...
# 6
I hv created an image using the img = createImage(new MemoryImageSource(iw,ih,pixels,0,iw));How can I save this image as a .bmp file on disk? please help me..
meghadeva at 2007-7-9 6:08:01 > top of Java-index,Security,Cryptography...