Solved

Convert Base-64 to jpeg

Posted on 2004-10-13
11
632 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Receive file in Servlet 1 36
wordappend challenge 8 88
base64 decode encode 12 100
HSSFWorkbook cannot be resolved error 10 23
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…
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…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

744 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

13 Experts available now in Live!

Get 1:1 Help Now