admin管理员组文章数量:1418411
I am making a function that pares two pictures if they are the same. I have this code:
var rez = null;
rez = pareImages();
alert(rez);
boolean
function pareImages() {
BufferedImage bi1 = java.ImageIO.read(new File("C:\\MyFiles\\pic1.png")),
bi2 = java.ImageIO.read(new File("C:\\MyFiles\\pic2.png"));
Raster r1 = bi1.getData(),
r2 = bi2.getData();
DataBuffer db1 = r1.getDataBuffer(),
db2 = r2.getDataBuffer();
int size1 = db1.getSize(),
size2 = db2.getSize();
// checking if the files sizes are the same
if (size1 != size2)
return false;
// pixel by pixel check up
for (int i = 0; i < size1; i++)
if (db1.getElem(i) != db2.getElem(i))
return false;
return true;
}
Now I want to run this code in .js file but when I do I get an error, missing ";" error. So how do I make this function javascript patible ?
Thanks.
I am making a function that pares two pictures if they are the same. I have this code:
var rez = null;
rez = pareImages();
alert(rez);
boolean
function pareImages() {
BufferedImage bi1 = java.ImageIO.read(new File("C:\\MyFiles\\pic1.png")),
bi2 = java.ImageIO.read(new File("C:\\MyFiles\\pic2.png"));
Raster r1 = bi1.getData(),
r2 = bi2.getData();
DataBuffer db1 = r1.getDataBuffer(),
db2 = r2.getDataBuffer();
int size1 = db1.getSize(),
size2 = db2.getSize();
// checking if the files sizes are the same
if (size1 != size2)
return false;
// pixel by pixel check up
for (int i = 0; i < size1; i++)
if (db1.getElem(i) != db2.getElem(i))
return false;
return true;
}
Now I want to run this code in .js file but when I do I get an error, missing ";" error. So how do I make this function javascript patible ?
Thanks.
Share Improve this question edited Aug 9, 2022 at 10:51 Luca Kiebel 10.1k7 gold badges32 silver badges46 bronze badges asked Nov 17, 2012 at 0:16 edinvnodeedinvnode 3,5577 gold badges34 silver badges56 bronze badges 2- 1 en.wikipedia/wiki/JavaScript#JavaScript_and_Java – TheZ Commented Nov 17, 2012 at 0:27
- Write the javascript bytecode interpreter, that will prob help you. – Roman C Commented Nov 17, 2012 at 0:37
3 Answers
Reset to default 4Unfortunately Javacript and Java are pletely seperate languages, and the only thing which they have in mon in the name, therefore this is impossible.
If you want to learn about doing something similar in javascript then take a look at the File API's: https://developer.mozilla/en-US/docs/DOM/File_APIs
You can't run Java code in JavaScript. You can either pile your Java code as an applet and embed that in you page, or you just rewrite your code in JS. If you use the html5 canvas
and the getImageData()
function, this should be doable. That way you can easily interact with your code from JavaScript.
It is somewhat possible to use Java classes and APIs in code that you write in JavaScript with Mozilla Rhino.
Rhino is simply a JS interpret written in Java that is bundled with the JDK. It basically allows you to use the Java APIs with JS syntax, but on the other hand, there is no DOM API available and you can't run such scripts in a Web browser. They are run by the JVM.
本文标签: run java in javascriptStack Overflow
版权声明:本文标题:run java in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745273941a2651064.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论