List of usage examples for java.awt Transparency OPAQUE
int OPAQUE
To view the source code for java.awt Transparency OPAQUE.
Click Source Link
From source file:ComponentTest.java
public static void main(String[] args) { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, new int[] { 5, 6, 5 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); Color fifty = new Color(cs, new float[] { 1.0f, 1.0f, 1.0f }, 0); float[] components = fifty.getComponents(null); System.out.print("Original normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); System.out.println();//w ww . j a v a 2 s . c o m int[] unnormalized = cm.getUnnormalizedComponents(components, 0, null, 0); System.out.print("Original unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); Object pixel = cm.getDataElements(unnormalized, 0, (Object) null); System.out.print("Pixel samples: "); byte[] pixelBytes = (byte[]) pixel; for (int i = 0; i < 3; i++) System.out.print(pixelBytes[i] + " "); System.out.println(); unnormalized = cm.getComponents(pixel, null, 0); System.out.print("Derived unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); components = cm.getNormalizedComponents(unnormalized, 0, null, 0); System.out.print("Derived normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); System.out.println(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, new int[] { 5, 6, 5 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); Color fifty = new Color(cs, new float[] { 1.0f, 1.0f, 1.0f }, 0); float[] components = fifty.getComponents(null); System.out.print("Original normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); System.out.println();//from ww w .j a v a2 s. c o m int[] unnormalized = cm.getUnnormalizedComponents(components, 0, null, 0); System.out.print("Original unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); Object pixel = cm.getDataElements(unnormalized, 0, (Object) null); System.out.print("Pixel samples: "); byte[] pixelBytes = (byte[]) pixel; for (int i = 0; i < 3; i++) System.out.print(pixelBytes[i] + " "); System.out.println(); unnormalized = cm.getComponents(pixel, null, 0); System.out.print("Derived unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); components = cm.getNormalizedComponents(unnormalized, 0, null, 0); System.out.print("Derived normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); }
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.OPAQUE); }
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(); // Create an image that does not support transparency BufferedImage bimage = gc.createCompatibleImage(100, 100, Transparency.OPAQUE); }
From source file:Main.java
public static BufferedImage getScaledInstance(BufferedImage img, int targetWidth, int targetHeight, Object hint, boolean higherQuality) { int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage ret = img;// w w w . jav a 2 s . com int w, h; if (higherQuality) { // Use multi-step technique: start with original size, then // scale down in multiple passes with drawImage() // until the target size is reached w = img.getWidth(); h = img.getHeight(); } else { // Use one-step technique: scale directly from original // size to target size with a single drawImage() call w = targetWidth; h = targetHeight; } do { if (higherQuality && w > targetWidth) { w /= 2; if (w < targetWidth) { w = targetWidth; } } if (higherQuality && h > targetHeight) { h /= 2; if (h < targetHeight) { h = targetHeight; } } BufferedImage tmp = new BufferedImage(w, h, type); Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint); g2.drawImage(ret, 0, 0, w, h, null); g2.dispose(); ret = tmp; } while (w != targetWidth || h != targetHeight); return ret; }
From source file:Main.java
public static BufferedImage takeScreenShot(Component component, String... watermarks) { Dimension size = component.getSize(); BufferedImage screenshot = new BufferedImage(size.width, size.height, Transparency.OPAQUE); Graphics2D g = screenshot.createGraphics(); g.setClip(0, 0, size.width - 1, size.height - 1); component.update(g);//from w w w . j av a 2 s . c o m FontMetrics fm = g.getFontMetrics(); int y = fm.getDescent(); for (String watermark : watermarks) if (watermark != null) { int x = size.width - SwingUtilities.computeStringWidth(fm, watermark); g.setColor(Color.black); g.drawString(watermark, x, y); g.setColor(Color.white); g.drawString(watermark, x - 1, y - 1); y -= fm.getHeight(); } g.dispose(); return screenshot; }
From source file:Main.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }/*from www . j av a 2 s . co m*/ // 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 a va 2 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:com.springsecurity.plugin.util.ImageResizer.java
public BufferedImage scale(File icon, int targetWidth, int targetHeight) { BufferedImage ret = null;/* ww w . j a v a 2s . co m*/ if (icon.exists()) { try { BufferedImage img = ImageIO.read(icon); ret = img; int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage scratchImage = null; Graphics2D g2 = null; int w = img.getWidth(); int h = img.getHeight(); int prevW = w; int prevH = h; do { if (w > targetWidth) { w /= 2; w = (w < targetWidth) ? targetWidth : w; } if (h > targetHeight) { h /= 2; h = (h < targetHeight) ? targetHeight : h; } if (scratchImage == null) { scratchImage = new BufferedImage(w, h, type); g2 = scratchImage.createGraphics(); } g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(ret, 0, 0, w, h, 0, 0, prevW, prevH, null); prevW = w; prevH = h; ret = scratchImage; } while (w != targetWidth || h != targetHeight); if (g2 != null) { g2.dispose(); } if (targetWidth != ret.getWidth() || targetHeight != ret.getHeight()) { scratchImage = new BufferedImage(targetWidth, targetHeight, type); g2 = scratchImage.createGraphics(); g2.drawImage(ret, 0, 0, null); g2.dispose(); ret = scratchImage; } } catch (IOException e) { } } return ret; }
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// w ww . j a va2 s. c o 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; }