wood burning stoves 2.0
The moose likes Swing / AWT / SWT and the fly likes Converting an byte[] to an image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Converting an byte[] to an image" Watch "Converting an byte[] to an image" New topic

Converting an byte[] to an image

Zac Styris

Joined: Nov 04, 2005
Posts: 14
Hi everyyone

I want to convet an byte[] which i've received from a mobile phone in to a image (jpg/png) after i receive it on the J2SE server end. Please some one help me with the method which i can just convert a byte[] in to a image n store it on the hard drive of the computer.

Joe Ess

Joined: Oct 29, 2001
Posts: 9126

javax.imageio.ImageIO can do what you need.

[How To Ask Questions On JavaRanch]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
What is the format of the data in the byte array? if it is already in JFIF (that's jpeg) or PNG format, just use java.io.* to write the data to a file. In other words, is there really a *need* to convert the data to an image?
[ January 27, 2006: Message edited by: Jeff Albertson ]

There is no emoticon for what I am feeling!
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
You can use JAI.

After you have the RenderedOp you can manipulate it how you want. For exampple,

Rashid Mayes
http://www.hostj2me.com/ - http://www.worlddeveloper.org/
Zac Styris

Joined: Nov 04, 2005
Posts: 14
Thanks guys, Java.io just works fine n suits for wut i wanna do, thanks for helping again.

Rock on
I agree. Here's the link: http://aspose.com/file-tools
subject: Converting an byte[] to an image
jQuery in Action, 3rd edition