This is a small program named Xkeycode that enables you to
capture system screen. Once you run the code it will capture the screen
and save and png image in your system. so please try it out..
This example helps you to compare two images (either jpeg or png) using pixel. first the program check whether two images are of equal breadth and width, then it compare each pixel by pixel and return the output. The program will check whether the two images given resembles each other or not. This is one of the simplest way and pixel based.
/*
* Image comparison done here is using pixels
*
*/
public class ImageComparison {
public boolean compareTwoImages(File fileOne, File fileTwo) {
Boolean isTrue = true;
try{
Image imgOne = ImageIO.read(fileOne);
Image imgTwo = ImageIO.read(fileTwo);
BufferedImage bufImgOne = ImageIO.read(fileOne);
BufferedImage bufImgTwo = ImageIO.read(fileTwo);
int imgOneHt = bufImgOne.getHeight();
int imgTwoHt = bufImgTwo.getHeight();
int imgOneWt = bufImgOne.getWidth();
int imgTwoWt = bufImgTwo.getWidth();
if(imgOneHt!=imgTwoHt ||(imgOneWt!=imgTwoWt)){
System.out.println(" size are not equal ");
isTrue = false;
}
for(int x =0; x< imgOneHt; x++ ){
for(int y =0; y <imgOneWt ; y++){
if(bufImgOne.getRGB(x, y) != bufImgTwo.getRGB(x, y) ){
System.out.println(" size are not equal ");
isTrue = false;
break;
}
}
}
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return isTrue;
}
public static void main(String[] args) {
File f = new File("E:\\javaaptitude\\Oracle.jpeg");
File f2 = new File("E:\\javaaptitude\\Capgemini.jpeg");
ImageComparison imgComp = new ImageComparison();
System.out.println(imgComp.compareTwoImages(f, f2));
}
}
The above code is for image having same width and height, if the image height and width is different use this code
public boolean compareTwoImages(File fileOne, File fileTwo) {
Boolean isTrue = true;
try{
Image imgOne = ImageIO.read(fileOne);
Image imgTwo = ImageIO.read(fileTwo);
BufferedImage bufImgOne = ImageIO.read(fileOne);
BufferedImage bufImgTwo = ImageIO.read(fileTwo);
int imgOneHt = bufImgOne.getHeight();
int imgTwoHt = bufImgTwo.getHeight();
int imgOneWt = bufImgOne.getWidth();
int imgTwoWt = bufImgTwo.getWidth();
if(imgOneHt!=imgTwoHt ||(imgOneWt!=imgTwoWt)){
System.out.println(" size are not equal ");
isTrue = false;
}
for(int x =0; x < imgOneWt; x++ ){ //replace the loop, if needed
for(int y =0; y < imgOneHt ; y++){
if(bufImgOne.getRGB(x, y) != bufImgTwo.getRGB(x, y) ){
System.out.println(" rgb are not equal ");
isTrue = false;
break;
}
}
}
}catch (IOException e) {
e.printStackTrace();
}
return isTrue;
}
public static void main(String[] softwareEngineer) {
File OracleJava = new File("C:\\Image\FingerPrint\analysis.jpg");
File javaOracle = new File("C:\\Histogram\match\image.jpg");
ImageComparison imgComp = new ImageComparison();
System.out.println(imgComp.compareTwoImages( OracleJava , javaOracle));
}
}
from comments :-
To work the above code for different dimensional images the for loop has to replaced.
Change
the for loop to the following .... for(int x =0; x < imgOneWt; x++
){ for(int y =0; y < imgOneHt ; y++){ if(bufImgOne.getRGB(x, y) !=
bufImgTwo.getRGB(x, y) ){ System.out.println(" size are not equal ");
isTrue = false; break; } } }
Hope you had tried the above code. Read this for to know how to create a captcha image in java : java be lazy
The program show a small demonstration of how Audio chat works in java. Click on the link to get the code. Two or more user can audio chat with the application. The program is developed using networking and java packages.
Please try audio chatting program... dont forget to post your feed back.
did you ever tried two way chatting using java code. Here we use socket communication, thread for this program. click the below link to download the code. javablzy