displaying image from binary data using java
hi there,
i have created a swing applet displays me a url, what the url returns me is the image in binary format, and i want to show the complete image using that binary data
so how do i do it.
some thing like this :
URL url = new URL("http://192.168.1.1:8086/file-storage/download/Zerg.jpg?version_id=35688");
JEditorPane jep = new JEditorPane();
jep.setPage(url);
output is in binary on my applet window.
[477 byte] By [
ppdhans] at [2007-9-26 2:19:54]

Hey,
This displays an image from a url, you could check if your url is and image or not using URL.getFileName() and see if it ends in gif jpeg etc. and then display it this way.
hope it helps
Nick Hanlon
import java.awt.*;
import java.awt.Image.*;
import java.awt.Toolkit.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.text.html.*;
public class SimpleApp extends JFrame {
public static void main(String args[]) {
SimpleApp aFrame = new SimpleApp();
}
public SimpleApp() {
super("Frame");
/*JEditorPane jep = new JEditorPane();
jep.*/
try {
HTMLEditorKit htmlKit = new HTMLEditorKit();
JEditorPane ep = new JEditorPane();
try {
ep.setEditorKit(htmlKit);
BufferedReader in = new BufferedReader(
new StringReader(
"<HTML><IMG SRC=\"http://developer.java.sun.com/images/chiclet.row.gif\"></HTML>"));
htmlKit.read(in, ep.getDocument(),0);
getContentPane().setLayout(new BorderLayout());
setResizable(false);
getContentPane().add(ep, "North");
pack();
show();
} catch (javax.swing.text.BadLocationException e) {}
} catch (IOException e) {}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { System.exit(0); }
});
}
}