Solved

Convert Base-64 to jpeg

Posted on 2004-10-13
11
644 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
 
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
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.

 
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

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
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.

910 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

23 Experts available now in Live!

Get 1:1 Help Now