Base64 image into JTextPane?

What you have to do is parse the Base64 encoded image into a byte array, then load an image using a ByteArrayIn,putStream using that byte array.

What you have to do is parse the Base64 encoded image into a byte array, then load an image using a ByteArrayIn,putStream using that byte array. As an example, for decoding Base64, you can use javax.xml.bind. DatatypeConverter#parseBase64Binary.

Ok thank you I used this: public static byte decode(String str){ byte bt = null; try { sun.misc. BASE64Decoder decoder = new sun.misc. BASE64Decoder(); bt = decoder.

DecodeBuffer( str ); } catch (IOException e) { e.printStackTrace(); } return bt; } // and then byte parseImg = f. Decode(texte); ImageIcon image = new ImageIcon(parseImg, "asd"); jTextPane. InsertIcon(image); // but it doesn't dislay the image..could you help me?

– Nicolas Apr 29 '10 at 15:04 Well, without more infos, it will be hard to help you. Anyway, since there is no exception showing, I guess the Base64 decoder worked fine. As a consequence, issue come from the image icon creation.

According to ImageIcon constructor documentation, iamge should be " containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG" Is it your case? – Riduidel Apr 29 '10 at 15:30 thank you for your infos, I completed my question see below... – Nicolas Apr 30 '10 at 16:01.

I found out! Solution is to extend the HTMLEditorKit by overriding the getViewFactory in class javax.swing.text.html. HTMLEditorKit then rewrite in the ImageViewclass.

Java the loadImage method to support images base64 encoded!

Finally I also found out where I have to override, "loadimage" method. I should add conditional flow of src="foo" to load image, would be just image's link or image data itself. Now, all I'd write "JTextPane.

SetEditorKit(new MyExtendedHtmlEditorKit());". However, my problem is here. The method exists "ImageViewer.

Class create()HtmlFactory. Class(static inner class)HtmlEditorKit. Class > void loadImage()ImageViewer.

Class" That's deep nested ,those class have many object invisible from outside class and many static definition. So, this means I must build a whole tree from roots for just pick a leaf on the top of branch. I can't edit Java VM runtime directly, compile and distribute it.

I think this is IMPOSSIBLE, at least It's for sure for me!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions