Solved

Convert Base-64 to jpeg

Posted on 2004-10-13
11
645 Views
Last Modified: 2010-08-05
Hi experts,

I have a case where I recieve an image in an xml file which is stored in base-64 encoding and I need to strip this out and create a JPEG from it, problem is that I just dont know how. Any ideas are welcome.

Regs
D
0
Comment
Question by:davidnaude
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12296353
use a Base64 decoder to convert the string to binary, and create your image from that.
0
 

Author Comment

by:davidnaude
ID: 12296380
Thanks objects,

Do you have any examples, recomendations for a base-64 decoder?
0
 
LVL 92

Expert Comment

by:objects
ID: 12296394
there are lots around, even one from Sun.
http://mindprod.com/products.html#BASE64
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 92

Expert Comment

by:objects
ID: 12296397
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12296412
Image image = Toolkit.geDefaultToolkit().createImage(new sun.misc.BASE64Decoder().decodeBuffer(stringToDecode)));
0
 
LVL 92

Expert Comment

by:objects
ID: 12296416
byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(s);
0
 
LVL 92

Expert Comment

by:objects
ID: 12296422
java understands jpeg the image part is easy, let me know if you need more details
0
 
LVL 5

Expert Comment

by:Naeemg
ID: 12296425
0
 
LVL 5

Expert Comment

by:Naeemg
ID: 12296433
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 12296504
Try this:

byte[] imageBytes = new sun.misc.BASE64Decoder().decodeBuffer(stringToDecode);
BufferedImage bi = javax.imageio.ImageIO.read(new ByteArrayInputStream(imageBytes));
javax.imageio.ImageIO.write(bi, "jpg", new File("my.jpg"));
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12296732
8-)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet  URL Rewriting 1 36
xampp tool 12 48
servlet filter example 37 59
Adding multiple JVM environments to RedHat 6 7 18
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

776 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