?
Solved

Convert Base-64 to jpeg

Posted on 2004-10-13
11
Medium Priority
?
685 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
[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
  • 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
Technology Partners: 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!

 
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: 12296433
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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.
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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