aspose file tools*
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Convert image to byte[] and viceversa" Watch "Convert image to byte[] and viceversa" New topic
Author

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
Author
Rancher

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
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Too difficult for "beginning"; moving thread.
 
wood burning stoves
 
subject: Convert image to byte[] and viceversa