BufferedImageのピクセルの色を取得します。私はBufferedImageの背景を白に設定し、BufferedImageで(100,100)から(100,200)までの線を描きます。次に、BufferedImageをJPanelに描画します。ラインはありますが背景は白ではありません。どうして?BufferedImageのピクセルの色を取得します。
getRGBメソッドは、getRGB(100,100)でなくても、R、G、Bに対して0を返します。なにが問題ですか?
コード:gbi.setBackground(Color.white)
後
public class PixelColour extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
BufferedImage bi = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB);
Graphics2D gbi = bi.createGraphics();
gbi.setColor(Color.black);
gbi.setBackground(Color.white);
gbi.drawLine(100, 100, 100, 200);
g2.drawImage(bi, null, 0, 0);
int rgb = bi.getRGB(100, 100);
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = (rgb & 0xFF);
System.out.println(red + " " + green + " " + blue);
}
public static void main(String[] args) throws IOException{
PixelColour pc = new PixelColour();
JFrame frame = new JFrame("Pixel colour");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(pc);
frame.setSize(500,500);
frame.setVisible(true);
}
}
を出力します? http://stackoverflow.com/questions/36246988/cannot-get-colour-of-pixel-on-screen – gpasch
@gpasch私はそれをロボットの代わりにBufferedImageを使ってやろうとしています。 – Saiyan