java实现提取图片每一点的RGB

2025-01-02 05:34:51
推荐回答(2个)
回答1:

public class TestActionAction extends Action {
public void doSome(){
try {
//
//ImageIO.read("http://210.75.193.191:8080/Vector/4/3728/1275.png");
ImageIcon[] image={new ImageIcon("G://公司项目/Images/Map/157.png"),new ImageIcon("G://公司项目/Images/Map/158.png"),new ImageIcon("G://公司项目/Images/Map/159.png"),new ImageIcon("G://公司项目/Images/Map/160.png")};
//BufferedImage相当于一个画布,在存在于内存中
BufferedImage img=new BufferedImage((image.length)*256 ,256,BufferedImage.TYPE_INT_RGB);
//必须创建Graphics2D对象和drawImage,不然画出来的只是image.getIconWidth*image.getIconHeight()那么大一个全黑图像
Graphics2D gs=(Graphics2D)img.getGraphics();
for(int i=0;i String k="";
gs.
}
gs.drawImage(image[0].getImage(), 0, 0, image[0].getImageObserver());
int huabuwid=img.getWidth();
int huabuhid=img.getHeight();
for(int i=0;i for(int j=0;j //基于坐标取出相对应的RGB
int rgb=img.getRGB(i, j);
int R = (rgb & 0xff0000) >> 16;
int G = (rgb & 0xff00) >> 8;
int B = (rgb & 0xff);
rgb=((R*256)+G)*256+B;
//把RGB值设置进相对应的坐标
img.setRGB(i, j, rgb);
}
}
gs.drawImage(image[1].getImage(), 256, 0, image[1].getImageObserver());
for(int i=0;i for(int j=0;j //基于坐标取出相对应的RGB
int rgb=img.getRGB(i, j);
int R = (rgb & 0xff0000) >> 16;
int G = (rgb & 0xff00) >> 8;
int B = (rgb & 0xff);
rgb=((R*256)+G)*256+B;
//把RGB值设置进相对应的坐标
img.setRGB(i, j, rgb);
}
}
gs.drawImage(image[2].getImage(), 512, 0, image[2].getImageObserver());
for(int i=0;i for(int j=0;j //基于坐标取出相对应的RGB
int rgb=img.getRGB(i, j);
int R = (rgb & 0xff0000) >> 16;
int G = (rgb & 0xff00) >> 8;
int B = (rgb & 0xff);
rgb=((R*256)+G)*256+B;
//把RGB值设置进相对应的坐标
img.setRGB(i, j, rgb);
}
}
gs.drawImage(image[3].getImage(), 768, 0, image[3].getImageObserver());
for(int i=0;i for(int j=0;j //基于坐标取出相对应的RGB
int rgb=img.getRGB(i, j);
int R = (rgb & 0xff0000) >> 16;
int G = (rgb & 0xff00) >> 8;
int B = (rgb & 0xff);
rgb=((R*256)+G)*256+B;
//把RGB值设置进相对应的坐标
img.setRGB(i, j, rgb);
}
}
//释放Graphics2D对象
gs.dispose();
//以流的方式保存文件
FileOutputStream outfile = new FileOutputStream("G:/1.png" );
ImageOutputStream i=ImageIO.createImageOutputStream(outfile);
ImageIO.write(img, "png", i);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static void main(String[] args){
new TestActionAction().doSome();
}
}

回答2:

````50怎么够