⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pubfuncs.htm

📁 applet在線上繪圖,允許在瀏覽器上繪圖,最後儲存成各式的圖檔
💻 HTM
字号:
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <title>DrawCanvas public functions</title>
<link REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
</head>

<body>
<a href="./index.htm">CONTENTS</a>

<h3>DrawCanvas public functions</h3>

<p>The applet <a href="placing.htm#DrawCanvas">DrawCanvas</a> supports the following public functions,
which can be called from JavaScript:</p>

<p><font color="800000"><b>Caution!</b></font> IE5 on the MAC platform doesn't support JavaScript to Java communication.</p>

<table border="1" cellpadding="8">

<tr><td>
<pre>
<b>GetImage(format)</b>

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

Returns:
  The image in the specified format and extra encoded by <a href="base64.htm">method BASE64</a>.
</pre>
</td></tr>

<tr><td>
<pre>
<b>GetImage(width, height, format)</b>

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 <a href="base64.htm">method BASE64</a>.
</pre>
This function is usefull if you wish to obtain the image thumbnail.
</td></tr>

<tr><td>

<pre>
<b>IsChanged()</b>
Returns:
  <b>true</b> if the image was changed, otherwise returns <b>false</b>.
</pre>
</td></tr>

<tr><td>
<pre>
<b>LoadImage(imageURL)</b>

Parameters:
  imageURL - URL of the image to load.
             The URL may be specified as absolute or relative to the HTML page.
</pre>
</td></tr>

<tr><td>
<pre>
<b>SetImage(base64String)</b>

Parameters:
  base64String - image in "jpeg", "png", or "gif" format encoded by <a href="base64.htm">method BASE64</a>.
</pre>
</td></tr>

<tr><td>
<pre>
<b>SetClipart(base64String, x, y)</b>

Parameters:
  base64String - image in "jpeg", "png", or "gif" format encoded by <a href="base64.htm">method BASE64</a>.
  x - horizontal coordinate of the insertion point.
  y - vertical coordinate of the insertion point.
</pre>
</td></tr>

<tr><td>
<pre>
<b>GetSelectedImage(format)</b>

Parameters:
  format - image format ("jpeg", "png", or "gif").
  
Returns:
  Selected image in the specified format encoded with <a href="base64.htm">BASE64</a> method
  or empty string if nothing is selected.
</pre>
</td></tr>

</table>

<p><b>How to access the applet functions in JavaScript:</b></p>

<p>To access a function in JavaScript you have to specify the attribute <b>name</b> for the applet the DrawCanvas
   and call the function as 
   <pre>
      document.applets['<i>canvas_name</i>'].<i>afunc()</i>;</pre>
   where <i>canvas_name</i> is the value assigned to the attribute <b>name</b>, and <i>afunc</i> is the function you call.<br>
   Keep in mind the function names are case sensitive.
<p>

<p><b>Alive example:</b></p>

<p>This example makes the call <i>GetImage("png")</i> and displays the image data in the alert window.</p>

<table cellspacing="8"><tr>
<td valign="top">

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

</td>
<td valign="top">
  <p>Draw something on the canvas and press the button to see the image data<br>
     in PNG graphic format enocded by <a href="base64.htm">method BASE64</a> method.</p>
  <form>
    <input type="button" value="Show the image data" onclick="return showBase64Data()" >
  </form>
</td>
</table>

<script language="javascript">

function showBase64Data() {
    var image = document.applets["mycanvas"].GetImage("png");
    
    if (image != "") {
    	window.alert(image);
    }
    else {
	window.alert("Error extracting the image.\nMay be you didn't installed the appropriate license code");
    };  
}

</script>

<p><b>The example's source code</b></p>

<pre>
&lt;applet name="<b>mycanvas</b>" code="DrawCanvas.class" archive="painter.jar" width="200" height="100" &gt;
&lt;/applet&gt;

&lt;form&gt;
    &lt;input type="button" value="Show the image data" onclick="return showBase64Data()" &gt;
&lt;/form&gt;

&lt;script language="javascript"&gt;

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

&lt;/script&gt;
</pre>

</p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -