The third parameter is an ARGB value of 32 bits. This is laid out in the form of bits:
AAAAAAAA|RRRRRRRR|GGGGGGGG|BBBBBBBBB
See javadoc for BufferedImage.setRGB (if you are using BufferedImage, your question doesn't really say ...)
BufferedImage RGB. , RGB , TYPE_INT_ARGB, sRGB . IndexColorModel
.
int alpha = 255;
int red = 0;
int green = 255;
int blue = 0;
int argb = alpha << 24 + red << 16 + green << 8 + blue
image.setRGB(i, j, argb);
, getRGB() java.awt.Color,
image.setRGB(i, j, Color.green.getRGB());
, , :
public class StackOverflow27071351 {
private static class ImagePanel extends JPanel {
private BufferedImage image;
public ImagePanel(int width, int height, BufferedImage image) {
this.image = image;
image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); j++) {
image.setRGB(i, j, new Color(255, 0, 0, 127).getRGB());
}
}
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
int width = 640;
int height = 480;
frame.setSize(width, height);
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(new ImagePanel(width, height, image));
frame.setVisible(true);
}
}