Slove!!! how to convert BufferedImage Object to byte[]

Hi All,

I need to convert BufferedImage Object o byte[] variable

BufferedImage bi=new BufferedImage(image.getWidth(null),image.getHeight(null),BufferedImage.TYPE_INT_RGB);

Graphics2D imageGraphics=bi.createGraphics();

imageGraphics.drawImage(image,0,0,null);

BufferedImageOp op=new AffineTransformOp(AffineTransform.getScaleInstance(scalex_width,scalex_height),null);

bi=op.filter(bi,null);

This bi object is need to convert into byte[] output;

ouput=...........

Thanks

Sunil

[543 byte] By [satyasunil_java@yahoo.co.ina] at [2007-11-26 21:17:04]
# 1
Look at ImageIO and ByteArrayOutputStream.
CeciNEstPasUnProgrammeura at 2007-7-10 2:55:46 > top of Java-index,Java Essentials,Java Programming...
# 2
Please stop posting your messages double.
prometheuzza at 2007-7-10 2:55:46 > top of Java-index,Java Essentials,Java Programming...
# 3
BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_3BYTE_BGR); Raster raster = bi.getData(); DataBufferByte ddb = (DataBufferByte)raster.getDataBuffer(); byte[] bytes =
sabre150a at 2007-7-10 2:55:46 > top of Java-index,Java Essentials,Java Programming...
# 4
I am gettgin ClassCastException if did,What was other solution or please correct it..........
satyasunil_java@yahoo.co.ina at 2007-7-10 2:55:46 > top of Java-index,Java Essentials,Java Programming...
# 5
Grr, bad cross poster.
mlka at 2007-7-10 2:55:46 > top of Java-index,Java Essentials,Java Programming...
# 6

> I am gettgin ClassCastException if did,

>

> What was other solution or please correct it..........

You will get a ClassCastException if you specify the wrong sort of BufferedImage in the construction of the BufferedImage. I'm pretty sure that you will be able to use a DataBufferByte withBufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_3BYTE_BGR);

but if you specify BufferedImage.TYPE_INT_RGB you will need a DataBufferInt and then have to do some manipulation to convert the ints to bytes.

sabre150a at 2007-7-10 2:55:46 > top of Java-index,Java Essentials,Java Programming...