?
Solved

Convert Uncompressed JPEG Image to byte Array in Java

Posted on 2007-03-31
5
Medium Priority
?
6,821 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 18828820
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 100 total points
ID: 18830296
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
ID: 18830311
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

765 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