Ejemplo n.º 1
0
 public static BufferedImage tileImage(BufferedImage im, int width, int height) {
   GraphicsConfiguration gc =
       GraphicsEnvironment.getLocalGraphicsEnvironment()
           .getDefaultScreenDevice()
           .getDefaultConfiguration();
   int transparency = Transparency.OPAQUE; // Transparency.BITMASK;
   BufferedImage compatible = gc.createCompatibleImage(width, height, transparency);
   Graphics2D g = (Graphics2D) compatible.getGraphics();
   g.setPaint(new TexturePaint(im, new Rectangle(0, 0, im.getWidth(), im.getHeight())));
   g.fillRect(0, 0, width, height);
   return compatible;
 }
Ejemplo n.º 2
0
 /** Create empty image with given alpha mode that should be efficient on this display */
 public static BufferedImage createCompatibleImage(int width, int height, int transparency) {
   // try {
   GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
   GraphicsDevice gs = ge.getDefaultScreenDevice();
   GraphicsConfiguration gc = gs.getDefaultConfiguration();
   // always use bitmask transparency
   BufferedImage bimage = gc.createCompatibleImage(width, height, transparency);
   return bimage;
   // } catch (HeadlessException e) { // this exception is not in 1.2
   // The system does not have a screen
   //	e.printStackTrace();
   //	return null;
   // }
 }