This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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


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: 43905
    
  32
Too difficult for "beginning"; moving thread.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Convert image to byte[] and viceversa
 
It's not a secret anymore!