This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Convert image to byte[] and viceversa Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Convert image to byte[] and viceversa" Watch "Convert image to byte[] and viceversa" New topic

Convert image to byte[] and viceversa

Adriano Bellavita
Ranch Hand

Joined: Mar 11, 2010
Posts: 37
I use this method to convert an image to an array of byte

When I try to reconvert the byte array into an Image by this code

PS: a is the byte array, y is an int array obtained by converting byte array like this

but the final image I found on the desktop is not the real image!!! It has a black background with some vertical colored lines.

Where is my error? In the first or in the second part?
David Newton

Joined: Sep 29, 2008
Posts: 12617

I thought the byte data from a read was just the image data--does it include all the metadata included in the file format?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46412
Too difficult for "beginning"; moving thread.
I agree. Here's the link:
subject: Convert image to byte[] and viceversa
It's not a secret anymore!