I am making a function that compares two pictures if they are the same. I have this code:
var rez = null;
rez = compareImages();
alert(rez);
boolean
function compareImages() {
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 compatible ?
Thanks.
You can’t run Java code in JavaScript. You can either compile 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
canvasand thegetImageData()function, this should be doable. That way you can easily interact with your code from JavaScript.