@Override public BufferedImage makeIcon( final int width, final int height, final Path2D iconShape, final boolean allowAlpha) { final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = result.createGraphics(); g.setStroke(new BasicStroke(0.05f)); final Color c; if (allowAlpha) { c = new Color( this.color.getRed(), this.color.getGreen(), this.color.getBlue(), this.color.getAlpha()); } else { c = new Color(this.color.getRGB()); } if (iconShape != null) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setColor(c); final Shape path = makeTransformedPathForSize(width, height, iconShape); g.fill(path); } else { g.setColor(c); g.fillRect(0, 0, width, height); } g.dispose(); return result; }
public void paint(Graphics g) { gRef = (Graphics2D) g; // change size of font gRef.setFont(gRef.getFont().deriveFont(9.0f)); fmRef = g.getFontMetrics(); // Clear background if (Preferences.monochrome) { gRef.setColor(Preferences.whiteColor); } else { gRef.setColor(Preferences.backgroundColor); } gRef.fillRect(0, 0, getWidth(), getHeight()); // set colour to correct drawing colour if (Preferences.monochrome) { gRef.setColor(Preferences.blackColor); } else { gRef.setColor(Preferences.penColor); } gRef.translate(0, margin); // Call c code to draw tree gRef.scale(scale, scale); nativeDrawTree(); }
public VolatileImage renderBackgroundLayer(int LayerNumber) { // create hardware accellerated background layer (Volatile Image) backgroundLayer[LayerNumber] = this.getGraphicsConfiguration() .createCompatibleVolatileImage( loadedLevel.getWidth() * 16, loadedLevel.getHeight() * 16, Transparency.TRANSLUCENT); Graphics2D g2d = backgroundLayer[LayerNumber].createGraphics(); g2d.setComposite(AlphaComposite.Src); // Clear the image. g2d.setColor(new Color(0, 0, 0, 0)); g2d.fillRect( 0, 0, backgroundLayer[LayerNumber].getWidth(), backgroundLayer[LayerNumber].getHeight()); g2d.setBackground(new Color(0, 0, 0, 0)); g2d.setColor(new Color(1f, 1f, 1f, 1f)); for (int i = 0; i < backgroundLayer[LayerNumber].getWidth(this) / backgroundImage[LayerNumber].getWidth(this); i++) { g2d.drawImage( backgroundImage[LayerNumber], i * backgroundImage[LayerNumber].getWidth(this), 0, this); } return backgroundLayer[LayerNumber]; }
/** [Internal] */ private void paintBackground(Graphics2D g2, Color theBackground) { Color color1 = g2.getColor(); if (theBackground == null) theBackground = Color.white; g2.setColor(theBackground); g2.fillRect(0, 0, 30000, 30000); g2.setColor(color1); }
public static void saveImageResultsToPng(String prefix, ImageSearchHits hits, String queryImage) throws IOException { LinkedList<BufferedImage> results = new LinkedList<BufferedImage>(); int width = 0; for (int i = 0; i < hits.length(); i++) { // hits.score(i) // hits.doc(i).get("descriptorImageIdentifier") BufferedImage tmp = ImageIO.read(new FileInputStream(hits.doc(i).get("descriptorImageIdentifier"))); // if (tmp.getHeight() > 200) { double factor = 200d / ((double) tmp.getHeight()); tmp = ImageUtils.scaleImage(tmp, (int) (tmp.getWidth() * factor), 200); // } width += tmp.getWidth() + 5; results.add(tmp); } BufferedImage result = new BufferedImage(width, 220, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D) result.getGraphics(); g2.setColor(Color.white); g2.setBackground(Color.white); g2.clearRect(0, 0, result.getWidth(), result.getHeight()); g2.setColor(Color.black); g2.setFont(Font.decode("\"Arial\", Font.BOLD, 12")); int offset = 0; int count = 0; for (Iterator<BufferedImage> iterator = results.iterator(); iterator.hasNext(); ) { BufferedImage next = iterator.next(); g2.drawImage(next, offset, 20, null); g2.drawString(hits.score(count) + "", offset + 5, 12); offset += next.getWidth() + 5; count++; } ImageIO.write( result, "PNG", new File(prefix + "_" + (System.currentTimeMillis() / 1000) + ".png")); }
public void drawCluster(Cluster cluster) { int index = clusters.indexOf(cluster); if (index != -1) { cluster.y = maxY; cluster.x = minX + index * factor; if (cluster.size() > 1) g.setColor(Color.RED); else g.setColor(Color.BLACK); g.drawRect(cluster.x - 1, cluster.y - cluster.size(), 2, 1 + cluster.size()); } else { Cluster left = cluster.getLeft(); Cluster right = cluster.getRight(); drawCluster(left); drawCluster(right); int yBar = minY + (int) ((maxY - minY) * (cluster.getSimilarity() / threshold)); g.setColor(Color.DARK_GRAY); if (left.y > yBar) { g.drawLine(left.x, left.y - 1, left.x, yBar); writeMap(left, yBar); } if (right.y > yBar) { g.drawLine(right.x, right.y - 1, right.x, yBar); writeMap(right, yBar); } g.setColor(Color.BLACK); g.drawLine(left.x, yBar, right.x, yBar); cluster.x = (right.x + left.x) / 2; cluster.y = yBar; } }
/** PaintComponent to draw everything. */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(Color.WHITE); // If using images, use cool dragon background if (useImages) g.drawImage(background, 0, 0, 310, 300, null); // Use light gray to not overpower the background image g.setColor(Color.LIGHT_GRAY); for (int y = 1; y < ROWS; ++y) g.fillRoundRect(0, cellSize * y - 4, (cellSize * COLS) - 1, 8, 8, 8); for (int x = 1; x < COLS; ++x) g.fillRoundRect(cellSize * x - 4, 0, 8, (cellSize * ROWS) - 1, 8, 8); // Use graphics2d for when not using the images Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); for (int y = 0; y < ROWS; ++y) { for (int x = 0; x < COLS; ++x) { int x1 = x * cellSize + 16; int y1 = y * cellSize + 16; if (board[y][x] == Symbol.X) { // use image if set to true, otherwise use g2d // for thicker, better looking X's and O's if (useImages) g.drawImage(imageX, x1, y1, 75, 75, null); else { g2d.setColor(PURPLE); int x2 = (x + 1) * cellSize - 16; int y2 = (y + 1) * cellSize - 16; g2d.drawLine(x1, y1, x2, y2); g2d.drawLine(x2, y1, x1, y2); } } else if (board[y][x] == Symbol.O) { if (useImages) g.drawImage(imageO, x1, y1, 75, 75, null); else { g2d.setColor(Color.BLUE); g2d.drawOval(x1, y1, 70, 70); } } } // end for } // Set status bar based on gamestate. If CONTINUE, show whose turn it is if (gameStatus == GameStatus.CONTINUE) { statusBar.setForeground(Color.BLACK); if (currentPlayer == Symbol.X) statusBar.setText("X's Turn"); else statusBar.setText("O's Turn"); } else if (gameStatus == GameStatus.DRAW) { statusBar.setForeground(Color.RED); statusBar.setText("Draw! Click to play again!"); } else if (gameStatus == GameStatus.X_WIN) { statusBar.setForeground(Color.RED); statusBar.setText("X has won! Click to play again!"); } else if (gameStatus == GameStatus.O_WIN) { statusBar.setForeground(Color.RED); statusBar.setText("O has won! Click to play again!"); } }
// initialize default image private BufferedImage getDefaultImage(int w, int h) { BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = defaultImage.createGraphics(); graphics2D.setColor(new Color(200, 200, 200)); graphics2D.fillRect(0, 0, w, h); graphics2D.setColor(new Color(130, 130, 130)); graphics2D.drawRect(0, 0, w - 1, h - 1); return defaultImage; }
public void paint(Graphics gOld) { if (image == null || xsize != getSize().width || ysize != getSize().height) { xsize = getSize().width; ysize = getSize().height; image = createImage(xsize, ysize); g = (Graphics2D) image.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } // fill background g.setColor(Color.cyan); g.fillRect(0, 0, xsize, ysize); int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)}; int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)}; // fill border g.setColor(Color.black); g.fillPolygon(x, y, 4); // draw border g.setColor(Color.red); g.drawPolyline(x, y, 5); if (animateFirstTime) { gOld.drawImage(image, 0, 0, null); return; } if (gameOver) return; g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this); for (int index = 0; index < missile.length; index++) { if (missile[index].active) { g.setColor(Color.red); drawCircle(getX(missile[index].xPos), getYNormal(missile[index].yPos), 90, .3, 1.5); } } if (rocketRight) { drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, 2.0, 2.0); } else { drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, -2.0, 2.0); } for (int index = 0; index < numStars; index++) { g.setColor(Color.yellow); if (starActive[index]) drawCircle(getX(starXPos[index]), getYNormal(starYPos[index]), 0, 1.5, 1.5); } g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("Score: " + score, 10, 45); g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("HighScore: " + highScore, 300, 45); g.setColor(Color.magenta); g.setFont(new Font("Impact", Font.BOLD, 15)); g.drawString("Lives: " + rocketLife, 150, 45); if (rocketLife == 0) { g.setColor(Color.red); g.setFont(new Font("Impact", Font.BOLD, 60)); g.drawString("GAME OVER", getX(getWidth2() / 6), getYNormal(getHeight2() / 2)); } gOld.drawImage(image, 0, 0, null); }
/* (non-Javadoc) * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int) */ public int print(Graphics g, PageFormat pf, int page) throws PrinterException { int ret = PAGE_EXISTS; String line = null; try { if (fph.knownPage(page)) { in.seek(fph.getFileOffset(page)); line = in.readLine(); } else { long offset = in.getFilePointer(); line = in.readLine(); if (line == null) { ret = NO_SUCH_PAGE; } else { fph.createPage(page); fph.setFileOffset(page, offset); } } if (ret == PAGE_EXISTS) { // Seite ausgeben, Grafikkontext vorbereiten Graphics2D g2 = (Graphics2D) g; g2.scale(1.0 / RESMUL, 1.0 / RESMUL); int ypos = (int) pf.getImageableY() * RESMUL; int xpos = ((int) pf.getImageableX() + 2) * RESMUL; int yd = 12 * RESMUL; int ymax = ypos + (int) pf.getImageableHeight() * RESMUL - yd; // Seitentitel ausgeben ypos += yd; g2.setColor(Color.black); g2.setFont(new Font("Monospaced", Font.BOLD, 10 * RESMUL)); g.drawString(fbname + " Seite " + (page + 1), xpos, ypos); g.drawLine( xpos, ypos + 6 * RESMUL, xpos + (int) pf.getImageableWidth() * RESMUL, ypos + 6 * RESMUL); ypos += 2 * yd; // Zeilen ausgeben g2.setColor(new Color(0, 0, 127)); g2.setFont(new Font("Monospaced", Font.PLAIN, 10 * RESMUL)); while (line != null) { g.drawString(line, xpos, ypos); ypos += yd; if (ypos >= ymax) { break; } line = in.readLine(); } } } catch (IOException e) { throw new PrinterException(e.toString()); } return ret; }
public void setPenColour(int colour) { if (Preferences.monochrome) { gRef.setColor(Preferences.blackColor); } else { if (colour == 0) { gRef.setColor(Preferences.penColor); } if (colour == 1) { gRef.setColor(Preferences.highlightColor); } } }
public void drawSelected(Graphics2D g2) { double r = type.getRadius(); Color c = type.getColor(); g2.setColor(c); int pixelsPerNm = DrawPanel.PIXELS_PER_NM; // In the drawPanel we map the z-coordinate to the x-coordinate int xint = (int) Math.round(pixelsPerNm * z); int yint = (int) Math.round(pixelsPerNm * y); int rint = (int) Math.round(pixelsPerNm * r); g2.fillOval(xint - rint, yint - rint, 2 * rint, 2 * rint); g2.setColor(Color.BLACK); g2.drawOval(xint - rint, yint - rint, 2 * rint, 2 * rint); }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.white); g2.fillRect(0, 0, getWidth(), getHeight()); AffineTransform at = new AffineTransform(0.5, 0, 0, -0.5, 30, getHeight() * 3 / 4); g2.transform(at); g2.setColor(Color.black); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // System.out.println("Showing="+showing); if (showing != null) { showing.draw(g2); } }
private BufferedImage createCustomImage() { BufferedImage image = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = image.createGraphics(); int dx = image.getWidth() / SQUARES; int dy = image.getHeight() / SQUARES; for (int i = 0; i < SQUARES; ++i) { for (int j = 0; j < SQUARES; ++j) { g2d.setColor(new Color(rand.nextInt())); g2d.fillRect(i * dx, j * dy, dx, dy); } } g2d.setColor(Color.GREEN); g2d.drawRect(0, 0, image.getWidth() - 1, image.getHeight() - 1); g2d.dispose(); return image; }
@Override public void paintComponent(Graphics window) { super.paintComponent(window); Image bufferedImage = createImage(getWidth(), getHeight()); Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); g2d.setPaint(gradient1); g2d.fillRect(0, 0, 300, 1000); if (showInstructions == true) { g2d.setColor(Color.YELLOW); g2d.setFont(font1); g2d.drawString("Instructions:", 10, 150); g2d.setFont(font3); g2d.drawString("To Play, Click New Game", 10, 200); g2d.drawString("Each game costs $1", 10, 230); g2d.drawString("Hit adds a card to your hand", 10, 260); g2d.drawString("Stand stops the game and", 10, 290); g2d.drawString("calculates each persons score", 10, 320); g2d.drawString("To play dealer, click Play Dealer", 10, 350); g2d.drawString("Enter your desired wager", 10, 380); g2d.drawString("Every time you score 20 or 21", 10, 470); g2d.drawString("you get one arcade token", 10, 500); g2d.drawString("Arcade Tokens can be redeemed", 10, 530); g2d.drawString("By closing instructions and clicking", 10, 560); g2d.drawString("Play Arcade Game", 10, 590); } else { g2d.setColor(Color.YELLOW); g2d.setFont(font1); g2d.drawString("Arcade Game:", 10, 250); g2d.setFont(font3); g2d.drawString("Select the game you would like", 10, 320); g2d.drawString("Click Play to Play.", 10, 350); g2d.drawString("Hold and Drag the Mouse", 10, 380); g2d.drawString("to move in Cube Runner", 10, 410); g2d.drawString("Press the mouse to sprint", 10, 440); g2d.drawString("in Spiral Game, and click", 10, 500); g2d.drawString("to Jump", 10, 530); g2d.drawString("Each game costs one token", 10, 560); g2d.drawString("", 10, 590); } g2d.setColor(Color.YELLOW); g2d.setFont(font1); g2d.drawString("Tokens: " + tempObject.tokens, 10, 700); window.drawImage(bufferedImage, 0, 0, this); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if (!text.equals("")) { g2.translate(0, getSize().getHeight()); g2.rotate(-Math.PI / 2); g2.setColor(Color.red); g2.fillRect(0, 0, sizeText_y, sizeText_x); g2.setColor(Color.white); g2.drawString(text, 20, 14); g2.translate(0, -getSize().getHeight()); g2.transform(AffineTransform.getQuadrantRotateInstance(1)); } }
public void plot(Color c, int x0, int y0, int z0) { Graphics2D g = bi.createGraphics(); g.setColor(c); if (x0 >= XRES || y0 >= YRES || x0 < 0 || y0 < 0) return; if (z0 > zbuffer[x0][y0]) { g.drawLine(x0, y0, x0, y0); zbuffer[x0][y0] = z0; } }
private void drawSnake(Graphics2D g) { g.setColor(panel.getColor()); for (BodyPart bodyPart : snake.getBody()) { g.fillRect( bodyPart.getX() * CELL_SIZE - CELL_SIZE, game.getScreenSize().height - (bodyPart.getY() * CELL_SIZE), CELL_SIZE, CELL_SIZE); } }
public void paint(Graphics g) { System.out.println("paint"); Graphics2D g2d = (Graphics2D) g; Point1 p1, p2; n = paintInfo.size(); if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除 for (int i = 0; i < n - 1; i++) { p1 = (Point1) paintInfo.elementAt(i); p2 = (Point1) paintInfo.elementAt(i + 1); size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); g2d.setColor(p1.col); g2d.setStroke(size); if (p1.tool == p2.tool) { switch (p1.tool) { case 0: // 画笔 Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line1); break; case 1: // 橡皮 g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder); break; case 3: // 画直线 Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line2); break; case 4: // 画圆 Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(ellipse); break; case 5: // 画矩形 Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(rect); break; case 6: // 截断,跳过 i = i + 1; break; default: } // end switch } // end if } // end for }
private void drawApple(Graphics2D g) { Color c = new Color(13, 111, 28); g.setColor(c); Image img1 = Toolkit.getDefaultToolkit().getImage("/apple.png"); g.drawImage(img1, apple.getX(), apple.getY(), CELL_SIZE, CELL_SIZE, null); g.fillRect( apple.getX() * CELL_SIZE - CELL_SIZE, game.getScreenSize().height - (apple.getY() * CELL_SIZE), CELL_SIZE, CELL_SIZE); }
public void draw(Graphics2D g) { g.setColor(fillColor); g.fill(gp); g.setColor(Color.black); g.draw(gp); for (int i = 0; i < points.size(); i++) { GlyphPoint p = points.get(i); g.setColor(Color.red); g.draw(p.gp); g.setColor(Color.blue); g.setFont(gfont); g.drawString(String.valueOf(i), p.x + 3, p.y + 3); } g.setColor(Color.black); // System.out.println("Advance: "+advance); g.draw(advp); if (name != null) { g.setFont(gfont); g.drawString(name, 0, -40); } }
public void write() { System.out.println("Writing image"); BufferedImage img = new BufferedImage(1600, 1200, BufferedImage.TYPE_INT_RGB); Graphics2D g = img.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, 1600, 1200); g.setColor(Color.black); counts = new double[depth]; for (int i = 0; i < depth; i++) { counts[i] = 0; } draw(root, g, 800, 10); try { File f = new File(jpeg); ImageIO.write((RenderedImage) img, "jpeg", f); } catch (Exception e) { System.out.println("Error writing image data"); } }
public int print(Graphics g,PageFormat pf,int pageIndex) { if (pageIndex == 0) { Graphics2D g2d= (Graphics2D)g; g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.setColor(Color.black); g2d.drawString("example string", 250, 250); g2d.fillRect(0, 0, 200, 200); return Printable.PAGE_EXISTS; } else { return Printable.NO_SUCH_PAGE; } }
@Override public void draw(Graphics2D g) { g.setColor(Color.lightGray); g.fillRect(0, 0, game.getScreenSize().width, game.getScreenSize().height); drawSnake(g); drawApple(g); g.setFont(new Font("Default", Font.BOLD, 12)); String message = "Press <F5> to save, <F6> to load."; Rectangle2D messageBounds = g.getFontMetrics() .getStringBounds( message, g); // g.getFontMetrics().getStringBounds - ��������� �������� ������ �������� // ������ � �������� int messageWidth = (int) (messageBounds.getWidth()); int messageHeight = (int) (messageBounds.getHeight()); g.drawString(message, 15, 10); if (paused) { g.setFont(new Font("Default", Font.BOLD, 60)); g.setColor(Color.white); message = "Pause"; messageBounds = g.getFontMetrics() .getStringBounds( message, g); // g.getFontMetrics().getStringBounds - ��������� �������� ������ �������� // ������ � �������� messageWidth = (int) (messageBounds.getWidth()); messageHeight = (int) (messageBounds.getHeight()); g.drawString( message, game.getScreenSize().width / 2 - messageWidth / 2, game.getScreenSize().height / 2 - messageHeight / 2); } }
public void draw(Graphics2D g) { if (AttributeKeys.FILL_COLOR.get(this) != null) { g.setColor(AttributeKeys.FILL_COLOR.get(this)); drawFill(g); } if (STROKE_COLOR.get(this) != null && STROKE_WIDTH.get(this) > 0d) { g.setStroke(AttributeKeys.getStroke(this)); g.setColor(STROKE_COLOR.get(this)); drawStroke(g); } if (TEXT_COLOR.get(this) != null) { if (TEXT_SHADOW_COLOR.get(this) != null && TEXT_SHADOW_OFFSET.get(this) != null) { Dimension2DDouble d = TEXT_SHADOW_OFFSET.get(this); g.translate(d.width, d.height); g.setColor(TEXT_SHADOW_COLOR.get(this)); drawText(g); g.translate(-d.width, -d.height); } g.setColor(TEXT_COLOR.get(this)); drawText(g); } }
public VolatileImage renderTileLayer() { // create hardware accellerated tile layer (Volatile Image) tileLayer = this.getGraphicsConfiguration() .createCompatibleVolatileImage( loadedLevel.getWidth() * 16, loadedLevel.getHeight() * 16, Transparency.TRANSLUCENT); Graphics2D g2d = tileLayer.createGraphics(); g2d.setComposite(AlphaComposite.Src); // Clear the image. g2d.setColor(new Color(0, 0, 0, 0)); g2d.fillRect(0, 0, tileLayer.getWidth(), tileLayer.getHeight()); g2d.setBackground(new Color(0, 0, 0, 0)); g2d.setColor(new Color(1f, 1f, 1f, 1f)); for (int i = 0; i < numberOfTiles; i++) { tile[i].draw(g2d, this); } return tileLayer; }
@Override public void prerasterizeIcon(final Shape shape) { final Rectangle r = shape.getBounds(); final BufferedImage prerasterized = new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = prerasterized.createGraphics(); g.setStroke(new BasicStroke(0.05f)); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setColor(this.color); g.fill(shape); g.dispose(); this.prerasterizedImage = prerasterized; }
public void draw( Graphics2D g, Color stringColor, Color foreground, Color background, String info, double x, double y) { FontMetrics fm = g.getFontMetrics(); int h = fm.getHeight(); int w = fm.stringWidth(info); r1.setRect( x - w / 2 - in.left, y - in.top - h / 2, w + in.right + in.left, h + in.bottom + in.top); g.setColor(background); g.fill(r1); g.setColor(stringColor); g.draw(r1); g.setColor(foreground); r2.setRect(r1.getX() + 1, r1.getY() + 1, r1.getWidth() - 2, r1.getHeight() - 2); g.draw(r2); g.setColor(stringColor); g.drawString( info, (float) (r2.getX() + in.left), (float) (r2.getY() + h - (r2.getHeight() - h) / 2)); }
public void initialize() { // openLevelFile images: try { boxSpriteSheet = ImageIO.read(new File("ItemContainer.png")); coinSpriteSheet = ImageIO.read(new File("Coin.png")); } catch (Exception e) { } if (openLevelFile == false) { try { loadLevel(initLevel); } catch (Exception e) { System.out.println(e); } } else { loadLevel(FileOpenDialog("Open ...")); } // create tile layer: renderTileLayer(); // create bg layer: backgroundLayer = new VolatileImage[backgroundImage.length]; // render layer: for (int i = 0; i < backgroundImage.length; i++) { renderBackgroundLayer(0); renderBackgroundLayer(1); } // create hardware accellerated rendering layer: renderImage = this.getGraphicsConfiguration() .createCompatibleVolatileImage( loadedLevel.getWidth() * 16, loadedLevel.getHeight() * 16, Transparency.TRANSLUCENT); Graphics2D g2d = renderImage.createGraphics(); g2d.setComposite(AlphaComposite.Src); // Clear the image. g2d.setColor(new Color(0, 0, 0, 0)); g2d.fillRect(0, 0, renderImage.getWidth(), renderImage.getHeight()); g2d.setBackground(new Color(0, 0, 0, 0)); }
static void paintFocus( Graphics g, int x, int y, int width, int height, int r1, int r2, float grosor, Color color) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Stroke oldStroke = g2d.getStroke(); g2d.setColor(color); g2d.setStroke(new BasicStroke(grosor)); if (r1 == 0 && r2 == 0) { g.drawRect(x, y, width, height); } else { g.drawRoundRect(x, y, width - 1, height - 1, r1, r2); } g2d.setStroke(oldStroke); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); }