• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 708
  • Last Modified:

Convert Base-64 to jpeg

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
davidnaude
Asked:
davidnaude
  • 5
  • 3
  • 2
  • +1
1 Solution
 
objectsCommented:
use a Base64 decoder to convert the string to binary, and create your image from that.
0
 
davidnaudeAuthor Commented:
Thanks objects,

Do you have any examples, recomendations for a base-64 decoder?
0
 
objectsCommented:
there are lots around, even one from Sun.
http://mindprod.com/products.html#BASE64
0
Industry Leaders: 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!

 
objectsCommented:
0
 
CEHJCommented:
Image image = Toolkit.geDefaultToolkit().createImage(new sun.misc.BASE64Decoder().decodeBuffer(stringToDecode)));
0
 
objectsCommented:
byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(s);
0
 
objectsCommented:
java understands jpeg the image part is easy, let me know if you need more details
0
 
NaeemgCommented:
0
 
CEHJCommented:
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
 
CEHJCommented:
8-)
0

Featured Post

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!

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now