It's not a secret anymore!
The moose likes Applets and the fly likes Saving a picture of an applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Saving a picture of an applet" Watch "Saving a picture of an applet" New topic

Saving a picture of an applet

Tokai Moshai

Joined: May 24, 2006
Posts: 16
I have an applet that shows a picture (I need that for many reasons and can't just show the picture).

Problem is, I cannot right click on the picture and do a 'Save Picture As..'. So, I'm trying to create a button, when clicked, will pop up the 'Save As..' so that users can save the picture on their computer.

How do I do that? In short, how do I get the 'Save picture as..' functionality inside JSP/HTML code?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
You can't. HTML and JavaScript have no concept of dealing with images (or files in general) in this way. The applet could do that if you gave it permission to access the local file system (which it is not allowed to access by default). This Wiki page explains how to do that.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

Moved to the Applets forum.

[Asking smart questions] [About Bear] [Books by Bear]
Manuel Moons
Ranch Hand

Joined: Mar 05, 2002
Posts: 229
If the applet can generate the picture the server can probably do the same.

The same parameters that are passed to the applet can be passed to a server process which returns you a "real" image. You might consider changing to such an implementation. In that case you do not have problems with applets anymore.

The other choice you have is opening up security for the applet and having it implement a popup when you right click on it which gives you the same options as another image. It is best however that you work with certificates and signing of the applet. Do not open up security for the whole VM (and thus for all applets).
Tokai Moshai

Joined: May 24, 2006
Posts: 16
thinking about solving it a bit different way. can I use the 'print screen' functionality (or even better a portion of the screen) using javascript? what I'm thinking is, clicking on a button will copy a portion of the web page to the clipboard and then users can do whatever they want to do with it.

I'll look into the security thing, thanks for the idea.
I agree. Here's the link:
subject: Saving a picture of an applet
It's not a secret anymore!