Solved

Convert Uncompressed JPEG Image to byte Array in Java

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

696 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