Solved

Convert Uncompressed JPEG Image to byte Array in Java

Posted on 2007-03-31
5
6,795 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
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 25 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

895 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

13 Experts available now in Live!

Get 1:1 Help Now