Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > convert BufferedImage to a byte array

Thread Tools

convert BufferedImage to a byte array opalinski from opalpaweb
Posts: n/a
You can serialize ImageIcon after making an ImageIcon from

Opalinski Removed)

Reply With Quote
greejose greejose is offline
Junior Member
Join Date: Jun 2008
Posts: 1
When I create my cropped image it is showing as a black square. The width and the height are correct but it is not "cropping" from the original image. Any help would be appreciated thanks!

String sp = "C:\\testin.jpg";
Image image = new ImageIcon(sp).getImage();
//image = (Image) request.getSession().getAttribute("fixed_image");

BufferedImage resizedImage = new BufferedImage(200, 200,BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = resizedImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INT ERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics2D.drawImage(image, 0,0, 80, 80, null, null);

BufferedImage croppedImage = resizedImage.getSubimage(1, 90, 90, 90);
File tempout = new File("C:\\testout.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
//FileOutputStream outImg = new FileOutputStream(tempimg);
ImageIO.write(croppedImage, "jpg", baos);
byte[] b = baos.toByteArray();

FileOutputStream outImg = new FileOutputStream(tempout);
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
convert form byte[4] to Int32 while retaining the binary value of the byte array C++ 20 09-07-2009 08:54 PM
How to convert a 4 byte character string to its equivalent 4 byte integer value? Polaris431 C Programming 8 12-04-2006 07:00 AM
Error when creating BufferedImage with IndexColorModel from a byte array. Java 1 10-11-2006 07:51 PM
convert byte[] to Byte[] Shane Wealti Java 5 06-13-2005 09:16 PM
Converting a Primative byte array to a Byte array object Kirby Java 3 10-08-2004 03:01 AM