Solved

Convert Uncompressed JPEG Image to byte Array in Java

Posted on 2007-03-31
5
6,783 Views
Last Modified: 2008-01-09
May i know how can i convert an uncompressed JPEG image into sequence of byte (i.e Byte Array) and vice versa (i.e convert from Byte Array to Uncompressed JPEG Image) using JAVA.
0
Comment
Question by:Angora
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 25 total points
Comment Utility
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(image, "JPEG", out);
byte[] imageBytes = out.toByteArray();

BufferedImage bi = ImageIO.read(new ByteArrayInputStream(imageBytes));
0
 
LVL 92

Assisted Solution

by:objects
objects earned 25 total points
Comment Utility
File jpeg = new File("my.jpg");
byte[] bytes = new byte[jpeg.length()];
DataInputStream in = new DataInputStream(new FileInputStream(jpeg));
in.readFully(bytes);
in.close();

// bytes will now contain contents of jpeg file

// to convert back to a file:

FileOutputStream out = new FileOutputStream("out.jpg");
out.write(bytes);
out.close();
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
The follpowing examples show good examples of reading/saving *Java* images if you need to use the jpeg as an Image in your application

http://www.exampledepot.com/egs/javax.imageio/BasicImageRead.html
http://www.exampledepot.com/egs/javax.imageio/Graphic2File.html
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now