How to reach a document.images.<image> object from an Applet?

A

Anders

Dear all,

I would like to be able to manipulate an image contained in a website using
an Applet. In order to do so I have to get the image inside the Applet.

My idea is to expose a public method in my Applet which is called when the
web page is loaded (i.e. onLoad)
The following is some pseudo code explaining what I'd like to do. If this is
at all possible, what type should the parameter for the passImage method
have and what properties for the document.images.picture should I send?

The image format could be of any common type (i.e. .gif, .jpg and maybe some
more)

Thanks,
/Anders
___________________________________________________
1. Java class:

[...]

public class AppletTest extends Applet{

private SomeImageClass myImage;

[...]

public void passImage(SomeImageClass myImage){
this.image = myImage;
}
}

2. HTML file:
<html>

[...]

<img name=picture src=picture.gif>
<applet name=TestApplet code=TestApplet.class width=1 height=1</applet>
<body
onLoad="document.TestApplet.passImage(document.images.picture.???)>
[...]
</body>
</html>
 
S

Scooby Ced

Anders said:
Dear all,

I would like to be able to manipulate an image contained in a website using
an Applet. In order to do so I have to get the image inside the Applet.

I suggest you to use the URL object:
<snipplet>
URL url;
Image img;
MediatTracker mt=new MediaTracker(this); // 'this' refers to the (J)Applet
object
Toolkit tk=this.getToolkit(); // 'this' refers to the (J)Applet object
try {
url=new URL("http","127.0.0.1","/foo/images/myImage.gif");
img=tk.getImage(url);
mt.addImage(img,0);
} catch(MalformedUrlException mue) {
System.err.println("Malformed URL");
}
mt.waitForID(0);
</snipplet>
 
A

Anders

Scooby Ced said:
I suggest you to use the URL object:
<snipplet>
URL url;
Image img;
MediatTracker mt=new MediaTracker(this); // 'this' refers to the (J)Applet
object
Toolkit tk=this.getToolkit(); // 'this' refers to the (J)Applet object
try {
url=new URL("http","127.0.0.1","/foo/images/myImage.gif");
img=tk.getImage(url);
mt.addImage(img,0);
} catch(MalformedUrlException mue) {
System.err.println("Malformed URL");
}
mt.waitForID(0);
</snipplet>

Thanks.

I see what you mean, but this will not work in my situation. I guess I was a
bit unclear reagarding the details. The image I'd like to manipulate in the
Applet is never stored on the server, but it is produced on-the-fly by a
servlet. Probably I could just transfer the image data from the servlet to
the applet but to do so in a robust way I guess this data has to be
serializeble; meaning not a compact form like gif or jpeg files.

Any more ideas? please.

Regards,
/Anders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top