Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在普通java编码中插入图像 import java.io.*; 导入java.awt.*; 导入javax.imageio.imageio; 导入java.awt.image.*; 导入java.awt.Image; 类比较{ 公共静态void main(字符串args[])引发IOException{ 长启动=System.currentTimeMillis(); File File=新文件(“C:\\Users\\Asus\\Desktop\\projek\\projekcodingjava\\JavaApplication22\\src\\training\u 1\u D.png”); BuffereImage image=ImageIO.read(文件); int width=image.getWidth(null); int height=image.getHeight(null); int[]clr=新int[宽度][高度]; File files=新文件(“C:\\Users\\Asus\\Desktop\\projek\\projekcodingjava\\JavaApplication22\\src\\training\u 1\u DB.png”); BuffereImage images=ImageIO.read(文件); int-widthe=images.getWidth(null); int height=images.getHeight(null); int[]clre=新int[widthe][heighte]; int smw=0; int-smh=0; int p=0; //计算宽度和高度之间的最小值 如果(宽度>宽度){smw=widthe;} else{smw=宽度;} 如果(高度>高度){smh=heighte;} else{smh=高度;} //检查像素数相似性 对于(int a=0;a_Java - Fatal编程技术网

在普通java编码中插入图像 import java.io.*; 导入java.awt.*; 导入javax.imageio.imageio; 导入java.awt.image.*; 导入java.awt.Image; 类比较{ 公共静态void main(字符串args[])引发IOException{ 长启动=System.currentTimeMillis(); File File=新文件(“C:\\Users\\Asus\\Desktop\\projek\\projekcodingjava\\JavaApplication22\\src\\training\u 1\u D.png”); BuffereImage image=ImageIO.read(文件); int width=image.getWidth(null); int height=image.getHeight(null); int[]clr=新int[宽度][高度]; File files=新文件(“C:\\Users\\Asus\\Desktop\\projek\\projekcodingjava\\JavaApplication22\\src\\training\u 1\u DB.png”); BuffereImage images=ImageIO.read(文件); int-widthe=images.getWidth(null); int height=images.getHeight(null); int[]clre=新int[widthe][heighte]; int smw=0; int-smh=0; int p=0; //计算宽度和高度之间的最小值 如果(宽度>宽度){smw=widthe;} else{smw=宽度;} 如果(高度>高度){smh=heighte;} else{smh=高度;} //检查像素数相似性 对于(int a=0;a

在普通java编码中插入图像 import java.io.*; 导入java.awt.*; 导入javax.imageio.imageio; 导入java.awt.image.*; 导入java.awt.Image; 类比较{ 公共静态void main(字符串args[])引发IOException{ 长启动=System.currentTimeMillis(); File File=新文件(“C:\\Users\\Asus\\Desktop\\projek\\projekcodingjava\\JavaApplication22\\src\\training\u 1\u D.png”); BuffereImage image=ImageIO.read(文件); int width=image.getWidth(null); int height=image.getHeight(null); int[]clr=新int[宽度][高度]; File files=新文件(“C:\\Users\\Asus\\Desktop\\projek\\projekcodingjava\\JavaApplication22\\src\\training\u 1\u DB.png”); BuffereImage images=ImageIO.read(文件); int-widthe=images.getWidth(null); int height=images.getHeight(null); int[]clre=新int[widthe][heighte]; int smw=0; int-smh=0; int p=0; //计算宽度和高度之间的最小值 如果(宽度>宽度){smw=widthe;} else{smw=宽度;} 如果(高度>高度){smh=heighte;} else{smh=高度;} //检查像素数相似性 对于(int a=0;a,java,Java,,这里有一个函数,您可以将图像文件的路径传递到该函数以将其输出:- import java.io.*; import java.awt.*; import javax.imageio.ImageIO; import java.awt.image.*; import java.awt.Image; class comparision{ public static void main(String args[]) throws IOException{ long start = Syst

,这里有一个函数,您可以将图像文件的路径传递到该函数以将其输出:-

import java.io.*;
import java.awt.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.awt.Image;



class comparision{

  public static void main(String args[]) throws IOException{
long start = System.currentTimeMillis();
    File file= new File("C:\\Users\\Asus\\Desktop\\projek\\projekcodingjava\\JavaApplication22\\src\\training_1_D.png");



    BufferedImage image = ImageIO.read(file);
 int width = image.getWidth(null);
    int height = image.getHeight(null);
int[][] clr=  new int[width][height];
File files= new File("C:\\Users\\Asus\\Desktop\\projek\\projekcodingjava\\JavaApplication22\\src\\training_1_DB.png");
    BufferedImage images = ImageIO.read(files);
 int widthe = images.getWidth(null);
    int heighte = images.getHeight(null);
int[][] clre=  new int[widthe][heighte];
int smw=0;
int smh=0;
int p=0;


//CALUCLATING THE SMALLEST VALUE AMONG WIDTH AND HEIGHT
if(width>widthe){ smw =widthe;}
else {smw=width;}
if(height>heighte){smh=heighte;}
else {smh=height;}



//CHECKING NUMBER OF PIXELS SIMILARITY
for(int a=0;a<smw;a++){
for(int b=0;b<smh;b++){
clre[a][b]=images.getRGB(a,b);
clr[a][b]=image.getRGB(a,b);
if(clr[a][b]==clre[a][b]) {
    p=p+1;
/*              { //to set if color match between two image (image A and Image B), appear BLACK
                    red = 0;
                         green = 0;
                            blue = 0;

                }
                else
                { //to set if color dont match between two image, appear WHITE
                    red = 255;
                            green = 255;
                                blue = 255;
                }

                pixel_data[color++] = (red << 16) | (green << 8 ) | blue);*/
}
}}

float w,h=0;
if(width>widthe) {w=width;}
else {w=widthe;}
if(height>heighte){ h = height;}
else{h = heighte;}
float s = (smw*smh);
//CALUCLATING PERCENTAGE
float x =(100*p)/s;

System.out.println("THE PERCENTAGE SIMILARITY IS APPROXIMATELY ="+x+"%");
long stop = System.currentTimeMillis();
System.out.println("TIME TAKEN IS ="+(stop-start));

  }

   //I WANT TO APPEAR THE IMAGE HERE. RETURN BLACK PIXEL IF PIXEL MATCH BETWEEN TWO IMAGE (IMAGE A AND IMAGE B) AND RETURN WHITE IF PIXEL DOSNT MATCH



}
拍摄两张黑白图像,然后在希望其显示的最后(//我想在此处显示图像。如果两张图像(图像A和图像B)之间的像素匹配,则返回黑色像素;如果像素不匹配,则返回白色”)放入一条检查匹配百分比的IF语句,即:-

// the imports required
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;

//paste this function in your class and call it when you want to display image

public void showImage(String path_to_image)
{
    JFrame frame = new JFrame("Image");
    frame.setLayout(new BorderLayout());
    frame.setResizable(false);
    ImageIcon myImage = new ImageIcon(path_to_image);
    frame.getContentPane().add(new JLabel(myImage));

    frame.pack();
    frame.setVisible(true);
}

如果你想要一个GUI程序,你应该搜索Java Swing或JavaFX。如果有人可以将此代码转换为GUI代码…这是工作,但我想比较两个图像的百分比&我想根据我的代码在百分比输出下面添加图像。
if(x == 100) // means 100 % match as per your code
{
  showImage("Black.png"); // path to black pic
}
else
{
  showImage("White.png"); // path to white pic
}