List of usage examples for java.awt Graphics2D fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:CompositingDST_ATOP.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST_OUT, 0.5f); BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); gbi.setPaint(Color.red);/*from ww w. j av a 2 s. co 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:util.ui.UiUtilities.java
/** * Scales an image to a specific size and returns an BufferedImage * * @param img//w w w .j a va2 s . co m * Scale this image * @param width * new width * @param height * new height * @param type The type of the image. * @return Scaled BufferedImage * * @since 3.0 */ public static BufferedImage scaleIconToBufferedImage(BufferedImage img, int width, int height, int type, Color backgroundColor) { // Scale Image Image image = img.getScaledInstance(width, height, Image.SCALE_SMOOTH); BufferedImage im = new BufferedImage(width, height, type); Graphics2D g2 = im.createGraphics(); if (backgroundColor != null) { g2.setColor(backgroundColor); g2.fillRect(0, 0, width, height); } g2.drawImage(image, null, null); g2.dispose(); im.flush(); return im; }
From source file:Main.java
public MyPanel() { this.setLayout(new GridLayout()); this.setPreferredSize(new Dimension(W, H)); int w = W / 2; int h = H / 2; int r = w / 5; BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.setColor(Color.gray);/*from w ww . j a v a2s . co m*/ g.fillRect(0, 0, w, h); g.setColor(Color.blue); g.fillRect(w / 2 - r, h / 2 - r / 2, 2 * r, r); g.dispose(); this.add(new JLabel(new ImageIcon(bi), JLabel.CENTER)); }
From source file:TexturePaintDemo.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); Graphics2D big = bi.createGraphics(); big.setColor(Color.blue);// w w w.java 2 s . co m big.fillRect(0, 0, 5, 5); big.setColor(Color.lightGray); big.fillOval(0, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); g2.setPaint(new TexturePaint(bi, r)); Rectangle rect = new Rectangle(5, 5, 200, 200); g2.fill(rect); }
From source file:TexturedText.java
private BufferedImage getTextureImage() { // Create the test image. int size = 8; BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bi.createGraphics(); g2.setPaint(Color.red);//from w w w . ja v a 2s . c o m g2.fillRect(0, 0, size / 2, size / 2); g2.setPaint(Color.yellow); g2.fillRect(size / 2, 0, size, size / 2); g2.setPaint(Color.green); g2.fillRect(0, size / 2, size / 2, size); g2.setPaint(Color.blue); g2.fillRect(size / 2, size / 2, size, size); return bi; }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; Ellipse2D e = new Ellipse2D.Float(10, 10, 200, 200); g2d.clip(e);/* www . ja v a 2 s .co m*/ g2d.fillRect(40, 60, 500, 500); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { int width = this.getWidth(); int height = this.getHeight(); float startPointX = 0.0f; float startPointY = 0.0f; float endPointX = width; float endPointY = 0.0f; Color startColor = new Color(red, green, blue, 255); Color endColor = new Color(red, green, blue, 0); Paint paint = new GradientPaint(startPointX, startPointY, startColor, endPointX, endPointY, endColor); Graphics2D g2D = (Graphics2D) g; g2D.setPaint(paint);/* ww w . j a va2 s . c om*/ g2D.fillRect(0, 0, width, height); }
From source file:Scale.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(150, 150, 150)); g2d.fillRect(0, 0, 80, 50); AffineTransform tx1 = new AffineTransform(); tx1.translate(110, 20);//from w w w . j a v a 2 s . c o m tx1.scale(0.5, 0.5); g2d.setTransform(tx1); g2d.fillRect(0, 0, 80, 50); AffineTransform tx2 = new AffineTransform(); tx2.translate(200, 20); tx2.scale(1.5, 1.5); g2d.setTransform(tx2); g2d.fillRect(0, 0, 80, 50); }
From source file:TextQualityDemoVALUE_TEXT_ANTIALIAS_LCD_HBGR.java
public void paintComponent(Graphics g) { Dimension d = this.getSize(); BufferedImage backBuffer = (BufferedImage) this.createImage(d.width, d.height); Graphics2D g2 = backBuffer.createGraphics(); g2.setColor(Color.WHITE);/* ww w.j a v a 2 s . c om*/ g2.fillRect(0, 0, d.width, d.height); g2.setColor(Color.BLACK); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, hintValue); g2.drawRect(0, 0, d.width - 1, d.height - 1); g2.drawString("abcdefghijklmnopqrstuvwxyz", 20, 40); g2.drawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 20, 60); g2.drawString("1234567890-=!@#$%^&*()_+,./<>?", 20, 80); g.drawImage(backBuffer, 0, 0, this); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(getBackground());/* w w w . j a v a 2 s . c om*/ g2d.fillRect(0, 0, getWidth(), getHeight()); if (image != null) { int x = getWidth() - image.getWidth(); int y = getHeight() - image.getHeight(); g2d.drawImage(image, x, y, this); } super.paintComponent(g2d); g2d.dispose(); }