CONTENTS

DrawCanvas public functions

The applet DrawCanvas supports the following public functions, which can be called from JavaScript:

Caution! IE5 on the MAC platform doesn't support JavaScript to Java communication.

GetImage(format)

Parameters:
  format - image format ("jpeg", "png", or "gif")

Returns:
  The image in the specified format and extra encoded by method BASE64.
GetImage(width, height, format)

Parameters:
  width  - image width  in pixels
  height - image height in pixels
  format - image format ("jpeg", "png",  or "gif")

Returns:
  The image scaled to the specified [width x height],
  encoded in the specified format, and extra encoded by method BASE64.
This function is usefull if you wish to obtain the image thumbnail.
IsChanged()
Returns:
  true if the image was changed, otherwise returns false.
LoadImage(imageURL)

Parameters:
  imageURL - URL of the image to load.
             The URL may be specified as absolute or relative to the HTML page.
SetImage(base64String)

Parameters:
  base64String - image in "jpeg", "png", or "gif" format encoded by method BASE64.
SetClipart(base64String, x, y)

Parameters:
  base64String - image in "jpeg", "png", or "gif" format encoded by method BASE64.
  x - horizontal coordinate of the insertion point.
  y - vertical coordinate of the insertion point.
GetSelectedImage(format)

Parameters:
  format - image format ("jpeg", "png", or "gif").
  
Returns:
  Selected image in the specified format encoded with BASE64 method
  or empty string if nothing is selected.

How to access the applet functions in JavaScript:

To access a function in JavaScript you have to specify the attribute name for the applet the DrawCanvas and call the function as

      document.applets['canvas_name'].afunc();
where canvas_name is the value assigned to the attribute name, and afunc is the function you call.
Keep in mind the function names are case sensitive.

Alive example:

This example makes the call GetImage("png") and displays the image data in the alert javascript dialog.

Draw something on the canvas and press the button to see the image data
in PNG graphic format enocded by method BASE64 method.

The example's source code

<applet name="mycanvas" code="DrawCanvas.class" archive="painter.jar" width="200" height="100" >
</applet>

<form>
    <input type="button" value="Show the image data" onclick="return showBase64Data()" >
</form>

<script language="javascript">

function showBase64Data() {
  var image = document.applets["mycanvas"].GetImage("png");
  window.alert(image);
}

</script>