Creating a Buffered Image by width and height and color model - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Color

Description

Creating a Buffered Image by width and height and color model


public void m() throws Exception {
  int width = 100;
  int height = 100;

  // Create buffered image that does not support transparency
  BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

  // Create a buffered image that supports transparency
  bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  GraphicsDevice gs = ge.getDefaultScreenDevice();
  GraphicsConfiguration gc = gs.getDefaultConfiguration();

  // Create an image that does not support transparency
  bimage = gc.createCompatibleImage(width, height, Transparency.OPAQUE);

  // Create an image that supports transparent pixels
  bimage = gc.createCompatibleImage(width, height, Transparency.BITMASK);

  // Create an image that supports arbitrary levels of transparency
  bimage = gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT);

}
  

Related Tutorials