List of usage examples for java.awt Transparency BITMASK
int BITMASK
To view the source code for java.awt Transparency BITMASK.
Click Source Link
From source file:Main.java
public static void main(String[] argv) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); System.out.println(gc.getColorModel(Transparency.BITMASK)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); BufferedImage bimage = gc.createCompatibleImage(100, 100, Transparency.BITMASK); }
From source file:Main.java
public static Image getImage(Component c) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); // Create an image that supports transparent pixels BufferedImage bImage = gc.createCompatibleImage(c.getWidth(), c.getHeight(), Transparency.BITMASK); /*// w ww . ja va 2 s . c o m * And now this is how we get an image of the component */ Graphics2D g = bImage.createGraphics(); // Then use the current component we're in and call paint on this // graphics object c.paint(g); return bImage; }
From source file:Main.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }/*from w ww . ja v a2 s . c o m*/ // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200, gc.getImageCapabilities(), Transparency.BITMASK); } catch (Exception e) { // The system does not have a screen } return bimage; }
From source file:Main.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }//from ww w . ja v a 2 s.com // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Determine if the image has transparent pixels; for this method's // implementation, see Determining If an Image Has Transparent Pixels boolean hasAlpha = true; // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { // Determine the type of transparency of the new buffered image int transparency = Transparency.OPAQUE; if (hasAlpha) { transparency = Transparency.BITMASK; } // Create the buffered image GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency); } catch (HeadlessException e) { // The system does not have a screen } if (bimage == null) { // Create a buffered image using the default color model int type = BufferedImage.TYPE_INT_RGB; if (hasAlpha) { type = BufferedImage.TYPE_INT_ARGB; } bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); } // Copy image to buffered image Graphics g = bimage.createGraphics(); // Paint the image onto the buffered image g.drawImage(image, 0, 0, null); g.dispose(); return bimage; }
From source file:ImageUtil.java
/** * Posted by alpha02 at http://www.dreamincode.net/code/snippet1076.htm *//*from ww w . j av a2 s . c o m*/ public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) return (BufferedImage) image; // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Determine if the image has transparent pixels boolean hasAlpha = hasAlpha(image); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { // Determine the type of transparency of the new buffered image int transparency = Transparency.OPAQUE; if (hasAlpha == true) transparency = Transparency.BITMASK; // Create the buffered image GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency); } catch (HeadlessException e) { } //No screen if (bimage == null) { // Create a buffered image using the default color model int type = BufferedImage.TYPE_INT_RGB; if (hasAlpha == true) { type = BufferedImage.TYPE_INT_ARGB; } bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); } // Copy image to buffered image Graphics g = bimage.createGraphics(); // Paint the image onto the buffered image g.drawImage(image, 0, 0, null); g.dispose(); return bimage; }
From source file:Main.java
/** * Create a custom cursor out of the specified image, with the specified hotspot. *///from ww w . j a v a 2 s .c o m public static Cursor createImageCursor(Image img, Point hotspot) { Toolkit tk = Toolkit.getDefaultToolkit(); // for now, just report the cursor restrictions, then blindly create int w = img.getWidth(null); int h = img.getHeight(null); Dimension d = tk.getBestCursorSize(w, h); // int colors = tk.getMaximumCursorColors(); // Log.debug("Creating custom cursor [desiredSize=" + w + "x" + h + // ", bestSize=" + d.width + "x" + d.height + // ", maxcolors=" + colors + "]."); // if the passed-in image is smaller, pad it with transparent pixels and use it anyway. if (((w < d.width) && (h <= d.height)) || ((w <= d.width) && (h < d.height))) { Image padder = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().createCompatibleImage(d.width, d.height, Transparency.BITMASK); Graphics g = padder.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); // and reassign the image to the padded image img = padder; // and adjust the 'best' to cheat the hotspot checking code d.width = w; d.height = h; } // make sure the hotspot is valid if (hotspot == null) { hotspot = new Point(d.width / 2, d.height / 2); } else { hotspot.x = Math.min(d.width - 1, Math.max(0, hotspot.x)); hotspot.y = Math.min(d.height - 1, Math.max(0, hotspot.y)); } // and create the cursor return tk.createCustomCursor(img, hotspot, "samskivertDnDCursor"); }
From source file:Main.java
/** * This method returns a buffered image with the contents of an image * This snippet was taken from: http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html * @param image/*www . j a v a2 s . co m*/ * @return The buffered image */ public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; } // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Determine if the image has transparent pixels; for this method's // implementation, see e661 Determining If an Image Has Transparent Pixels boolean hasAlpha = hasAlpha(image); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { // Determine the type of transparency of the new buffered image int transparency = Transparency.OPAQUE; if (hasAlpha) { transparency = Transparency.BITMASK; } // Create the buffered image GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency); } catch (HeadlessException e) { // The system does not have a screen } if (bimage == null) { // Create a buffered image using the default color model int type = BufferedImage.TYPE_INT_RGB; if (hasAlpha) { type = BufferedImage.TYPE_INT_ARGB; } bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); } // Copy image to buffered image Graphics g = bimage.createGraphics(); // Paint the image onto the buffered image g.drawImage(image, 0, 0, null); g.dispose(); return bimage; }
From source file:org.sonar.server.charts.deprecated.BaseChart.java
protected BufferedImage getBufferedImage(JFreeChart chart) { return chart.createBufferedImage(getWidth(), getHeight(), Transparency.BITMASK, null); }
From source file:com.t3.image.ImageUtil.java
/** * Look at the image and determine which Transparency is most appropriate. * If it finds any translucent pixels it returns Transparency.TRANSLUCENT, if * it finds at least one purely transparent pixel and no translucent pixels * it will return Transparency.BITMASK, in all other cases it returns * Transparency.OPAQUE, including errors * //from w ww. j av a 2 s.c o m * @param image * @return one of Transparency constants */ public static int pickBestTransparency(Image image) { // Take a shortcut if possible if (image instanceof BufferedImage) { return pickBestTransparency((BufferedImage) image); } // Legacy method // NOTE: This is a horrible memory hog int width = image.getWidth(null); int height = image.getHeight(null); int[] pixelArray = new int[width * height]; PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixelArray, 0, width); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); return Transparency.OPAQUE; } if ((pg.getStatus() & ImageObserver.ABORT) != 0) { System.err.println("image fetch aborted or errored"); return Transparency.OPAQUE; } // Look for specific pixels boolean foundTransparent = false; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // Get the next pixel int pixel = pixelArray[y * width + x]; int alpha = (pixel >> 24) & 0xff; // Is there translucency or just pure transparency ? if (alpha > 0 && alpha < 255) { return Transparency.TRANSLUCENT; } if (alpha == 0 && !foundTransparent) { foundTransparent = true; } } } return foundTransparent ? Transparency.BITMASK : Transparency.OPAQUE; }