List of usage examples for java.awt AlphaComposite Src
AlphaComposite Src
To view the source code for java.awt AlphaComposite Src.
Click Source Link
From source file:Main.java
public static BufferedImage asCompatibleImage(Image img, int transparency) { BufferedImage ret = defaultScreenDeviceConfiguration().createCompatibleImage(img.getWidth(null), img.getHeight(null), transparency); Graphics2D gc = ret.createGraphics(); gc.setComposite(AlphaComposite.Src); gc.drawImage(img, 0, 0, null);//from w w w .ja v a 2s .c om gc.dispose(); return ret; }
From source file:Main.java
/** * Resizes an image using bilinear filtering. * @param source the source image.// w ww. ja va 2s . c o m * @param newWidth the new image width. * @param newHeight the new image height. */ public static BufferedImage performResizeBilinear(BufferedImage source, int newWidth, int newHeight) { BufferedImage out = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = out.createGraphics(); g2d.setComposite(AlphaComposite.Src); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.drawImage(source, 0, 0, newWidth, newHeight, null); g2d.dispose(); return out; }
From source file:Main.java
/** * Resizes an image using trilinear filtering. * @param source the source image./*from ww w. j ava 2s .c o m*/ * @param newWidth the new image width. * @param newHeight the new image height. */ public static BufferedImage performResizeTrilinear(BufferedImage source, int newWidth, int newHeight) { BufferedImage out = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = out.createGraphics(); g2d.setComposite(AlphaComposite.Src); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.drawImage(source, 0, 0, newWidth, newHeight, null); g2d.dispose(); return out; }
From source file:CompositingDST_ATOP.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f); BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); gbi.setPaint(Color.red);//from w w w. java2 s .c o m gbi.fillRect(0, 0, 40, 40); gbi.setComposite(ac); gbi.setPaint(Color.green); gbi.fillRect(5, 5, 40, 40); g2d.drawImage(buffImg, 20, 20, null); }
From source file:Main.java
public static Image resize(Image i, int scale) { BufferedImage resizedImage = new BufferedImage(scale, scale, BufferedImage.TYPE_INT_ARGB); Graphics2D g = resizedImage.createGraphics(); g.drawImage(i, 0, 0, scale, scale, null); g.dispose();// w ww. j av a 2 s . c o m g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); return resizedImage; }
From source file:BasicShapes.java
public void paint(Graphics g) { BufferedImage bimage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED); Graphics2D g2d = bimage.createGraphics(); Color transparent = new Color(0, 0, 0, 0); g2d.setColor(transparent);//from w ww.jav a2 s. co m g2d.setComposite(AlphaComposite.Src); g2d.fill(new Rectangle2D.Float(20, 20, 100, 20)); g2d.dispose(); }
From source file:Main.java
private static BufferedImage resizeImageWithHint(BufferedImage originalImage, int type) { int IMG_WIDTH = 512; int IMG_CLAHEIGHT = 512; BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_CLAHEIGHT, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_CLAHEIGHT, null); g.dispose();/* ww w . j av a2s .co m*/ g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); return resizedImage; }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHints(rh);/*from w w w . ja v a 2s . co m*/ int x = 40, y = 40; g.setColor(Color.red); g.fillOval(x, y, 50, 50); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC)); g.setColor(Color.green); g.fillOval(x + 30, y + 30, 30, 30); g2.setComposite(old); g.setColor(Color.black); g.drawString("AlphaComposite.SRC", x, y + 80); }
From source file:com.taunova.app.libview.components.ImageHelpers.java
public static Image getScaledImage(BufferedImage image, int width) { Dimension d = getScaledDimension(image, width); Image scaledImage = image.getScaledInstance(d.width, d.height, Image.SCALE_SMOOTH); BufferedImage resizedImage = null; final boolean OPTIMIZE_SCALE = true; if (OPTIMIZE_SCALE) { ResampleOp resampleOp = new ResampleOp(100, 200); resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal); resizedImage = resampleOp.filter(image, null); } else {/*ww w.java 2s .co m*/ resizedImage = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB); Graphics2D g = resizedImage.createGraphics(); g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawImage(scaledImage, 0, 0, d.width, d.height, null); g.dispose(); } return resizedImage; }
From source file:com.github.lucapino.sheetmaker.PreviewJFrame.java
public static BufferedImage makeRoundedCorner(BufferedImage image, int cornerRadius) { int w = image.getWidth(); int h = image.getHeight(); BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); // This is what we want, but it only does hard-clipping, i.e. aliasing // g2.setClip(new RoundRectangle2D ...) // so instead fake soft-clipping by first drawing the desired clip shape // in fully opaque white with antialiasing enabled... g2.setComposite(AlphaComposite.Src); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE);//from ww w . ja v a2s .c o m g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius)); // ... then compositing the image on top, // using the white shape from above as alpha source g2.setComposite(AlphaComposite.SrcIn); g2.drawImage(image, 0, 0, null); g2.dispose(); return output; }