我有 JAVA 代码
import java.applet.Applet; import java.awt.Container; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.Image; import java.awt.MediaTracker; import java.awt.TextArea; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.awt.image.ImageProducer; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO;
public class JavaScriptToJava extends Applet{
TextArea textBox;
Image img;
MediaTracker tr;
public void init(){
setLayout(new FlowLayout());
textBox = new TextArea(5,40);
add(textBox);
}
public void appendText(String text){
textBox.append(text);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
try {
//Get data from clipboard and assign it to an image.
//clipboard.getData() returns an object, so we need to cast it to a BufferdImage.
BufferedImage image = (BufferedImage)clipboard.getData(DataFlavor.imageFlavor);
}
//getData throws this.
catch(UnsupportedFlavorException ufe) {
ufe.printStackTrace();
}
catch(IOException ioe) {
ioe.printStackTrace();
}
}
}
我需要在 javascript 中获取此图像。这是怎么做的?
我的主要任务是从剪贴板复制图像并将其传输到调用js的html页面