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]
# 1

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); }

});

}

}

nhanlon at 2007-6-29 9:22:58 > top of Java-index,Archived Forums,Java Programming...
# 2
the above code failed to display the image try adding this link of code in img scr tag in the code still it wont work. http://developer.java.sun.com/images/javalogo52x88.gifwhat should i do to make it run..if anyone..
ppdhans at 2007-6-29 9:22:58 > top of Java-index,Archived Forums,Java Programming...
# 3
An applet can only get images from the server from which the applet was downloaded from - unless you have singed it. Could this be the problem?
jsalonen at 2007-6-29 9:22:58 > top of Java-index,Archived Forums,Java Programming...