Solved

Convert Base-64 to jpeg

Posted on 2004-10-13
11
672 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 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…

726 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