java.awt.Graphics2D.fill()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(391)

本文整理了Java中java.awt.Graphics2D.fill()方法的一些代码示例,展示了Graphics2D.fill()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics2D.fill()方法的具体详情如下:
包路径:java.awt.Graphics2D
类名称:Graphics2D
方法名:fill

Graphics2D.fill介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
  g.setColor(color);
  try {
    g.fill(glyph.getShape()); // Java2D fails on some glyph shapes?!
  } catch (Throwable ignored) {
  }
}

代码示例来源:origin: runelite/runelite

private void renderPoly(Graphics2D graphics, Color color, Polygon polygon)
  {
    if (polygon != null)
    {
      graphics.setColor(color);
      graphics.setStroke(new BasicStroke(2));
      graphics.draw(polygon);
      graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20));
      graphics.fill(polygon);
    }
  }
}

代码示例来源:origin: libgdx/libgdx

public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
  int ascent = unicodeFont.getAscent();
  float height = (ascent) * scale;
  float top = -glyph.getYOffset() + unicodeFont.getDescent() + offset + ascent / 2 - height / 2;
  g.setPaint(new GradientPaint(0, top, topColor, 0, top + height, bottomColor, cyclic));
  g.fill(glyph.getShape());
}

代码示例来源:origin: plantuml/plantuml

g2.setColor(Color.white);
g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND));
      translate.setToTranslation(offset, offset);
      shadow.transform(translate);
      g2.setColor(new Color(150,150,150));
      g2.fill(shadow);
 new BasicStroke(
  strokeWeight,
      g2.setColor(shape.getFillColor());
    g2.fill(path);
    g2.setStroke(dashStroke);
  g2.draw(path);
    g2.fill(path);
    g2.draw(path);
  g2.fill(path);
  g2.setColor(shape.getStrokeColor());
  g2.draw(path);

代码示例来源:origin: runelite/runelite

private Ellipse2D drawEllipse(Graphics2D graphics, int x, int y)
{
  graphics.setColor(config.progressOrbBackgroundColor());
  Ellipse2D ellipse = new Ellipse2D.Double(x, y, config.xpOrbSize(), config.xpOrbSize());
  graphics.fill(ellipse);
  graphics.draw(ellipse);
  return ellipse;
}

代码示例来源:origin: plantuml/plantuml

final HtmlColor extended = fontConfiguration.getExtendedColor();
if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) {
  final Rectangle2D.Double area = new Rectangle2D.Double(x, y - dimBack.getHeight() + 1.5,
      dimBack.getWidth(), dimBack.getHeight());
  if (extended instanceof HtmlColorGradient) {
    final GradientPaint paint = DriverRectangleG2d.getPaintGradient(x, y, mapper, dimBack.getWidth(),
        dimBack.getHeight(), extended);
    g2d.setPaint(paint);
    g2d.fill(area);
  } else {
    final Color backColor = mapper.getMappedColor(extended);
    if (backColor != null) {
      g2d.setColor(backColor);
      g2d.setBackground(backColor);
      g2d.fill(area);
g2d.setColor(mapper.getMappedColor(fontConfiguration.getColor()));
g2d.drawString(shape.getText(), (float) x, (float) y);
    g2d.setColor(mapper.getMappedColor(extended));
  g2d.setStroke(new BasicStroke((float) 1));
  g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos);
  g2d.setStroke(new BasicStroke());
    g2d.setColor(mapper.getMappedColor(extended));

代码示例来源:origin: plantuml/plantuml

final boolean isLine = shape instanceof Line2D.Double;
if (isLine) {
  gg.setColor(colorLine);
  gg.draw(shape);
} else {
  gg.setColor(color);
  gg.fill(shape);

代码示例来源:origin: stackoverflow.com

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);
  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.SrcAtop);
  g2.drawImage(image, 0, 0, null);

  g2.dispose();

  return output;
}

代码示例来源:origin: apache/pdfbox

imageTransform.translate(0, -1);
Paint awtPaint = new TexturePaint(image,
    new Rectangle2D.Double(imageTransform.getTranslateX(), imageTransform.getTranslateY(),
        imageTransform.getScaleX(), imageTransform.getScaleY()));
awtPaint = applySoftMaskToPaint(awtPaint, softMask);
graphics.setPaint(awtPaint);
Rectangle2D unitRect = new Rectangle2D.Float(0, 0, 1, 1);
if (isContentRendered())
  graphics.fill(at.createTransformedShape(unitRect));

代码示例来源:origin: runelite/runelite

private void renderInventory(Graphics2D graphics)
{
  Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
  if (inventoryWidget == null || inventoryWidget.isHidden())
  {
    return;
  }
  for (WidgetItem item : inventoryWidget.getWidgetItems())
  {
    Rectangle slotBounds = item.getCanvasBounds();
    String idText = "" + item.getId();
    FontMetrics fm = graphics.getFontMetrics();
    Rectangle2D textBounds = fm.getStringBounds(idText, graphics);
    int textX = (int) (slotBounds.getX() + (slotBounds.getWidth() / 2) - (textBounds.getWidth() / 2));
    int textY = (int) (slotBounds.getY() + (slotBounds.getHeight() / 2) + (textBounds.getHeight() / 2));
    graphics.setColor(new Color(255, 255, 255, 65));
    graphics.fill(slotBounds);
    graphics.setColor(Color.BLACK);
    graphics.drawString(idText, textX + 1, textY + 1);
    graphics.setColor(YELLOW);
    graphics.drawString(idText, textX, textY);
  }
}

代码示例来源:origin: org.apache.poi/poi

protected void drawDecoration(Graphics2D graphics, Paint line, BasicStroke stroke) {
  if(line == null) {
    return;
  }
  graphics.setPaint(line);
  List<Outline> lst = new ArrayList<>();
  LineDecoration deco = getShape().getLineDecoration();
  Outline head = getHeadDecoration(graphics, deco, stroke);
  if (head != null) {
    lst.add(head);
  }
  Outline tail = getTailDecoration(graphics, deco, stroke);
  if (tail != null) {
    lst.add(tail);
  }
  for(Outline o : lst){
    java.awt.Shape s = o.getOutline();
    Path p = o.getPath();
    graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, s);
    if(p.isFilled()) {
      graphics.fill(s);
    }
    if(p.isStroked()) {
      graphics.draw(s);
    }
  }
}

代码示例来源:origin: runelite/runelite

@Override
public Dimension render(Graphics2D graphics)
{
  //Construct the arc
  Arc2D.Float arc = new Arc2D.Float(Arc2D.PIE);
  arc.setAngleStart(90);
  arc.setAngleExtent(progress * 360);
  arc.setFrame(position.getX() - diameter / 2, position.getY() - diameter / 2, diameter, diameter);
  //Draw the inside of the arc
  graphics.setColor(fill);
  graphics.fill(arc);
  //Draw the outlines of the arc
  graphics.setStroke(stroke);
  graphics.setColor(borderColor);
  graphics.drawOval(position.getX() - diameter / 2, position.getY() - diameter / 2, diameter, diameter);
  return new Dimension(diameter, diameter);
}

代码示例来源:origin: nodebox/nodebox

private void paintDragSelection(Graphics2D g) {
  if (isDragSelecting) {
    Rectangle r = dragSelectRect();
    g.setColor(DRAG_SELECTION_COLOR);
    g.setStroke(DRAG_SELECTION_STROKE);
    g.fill(r);
    // To get a smooth line we need to subtract one from the width and height.
    g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth() - 1, (int) r.getHeight() - 1);
  }
}

代码示例来源:origin: magefree/mage

Rectangle2D casing = new Rectangle2D.Double(0, 0, width, height);
g2.setColor(Color.BLACK);
g2.fill(casing);
g2.setComposite(composite);
Area area = new Area(casing);
area.subtract(new Area(roundCasing));
g2.fill(area);
Rectangle2D casing = new Rectangle2D.Double(0, 0, width, height);
g2.setColor(Color.BLACK);
g2.fill(casing);
g2.setComposite(composite);
Area area = new Area(casing);
area.subtract(new Area(roundCasing));
g2.fill(area);

代码示例来源:origin: nz.ac.waikato.cms.moa/moa

public void clearPoints() {
  Graphics2D imageGraphics = (Graphics2D) pointImg.createGraphics();
      
  imageGraphics.setColor(Color.WHITE);       
  imageGraphics.setPaint(Color.WHITE);
  imageGraphics.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
      ApplyToCanvas(pointImg);
  RedrawPointLayer();
}

代码示例来源:origin: knowm/XChart

@Override
 public void paint(Graphics2D g, double xOffset, double yOffset, int markerSize) {
  g.setStroke(stroke);
  double halfSize = (double) markerSize / 2;

  Shape square =
    new Rectangle2D.Double(xOffset - (halfSize / 2), yOffset - halfSize, halfSize, markerSize);
  g.fill(square);
 }
}

代码示例来源:origin: jenkinsci/jenkins

double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location);
g2.setPaint(getItemPaint(row, column));
g2.setStroke(getItemStroke(row, column));
      p.addPoint((int) xx0, (int) previousHeightxx0);
      g2.setPaint(getItemPaint(row, column-1));
      g2.setStroke(getItemStroke(row, column-1));
      g2.fill(p);
      p.addPoint((int) xx1, (int) previousHeightxx1);
      g2.setPaint(getItemPaint(row, column));
      g2.setStroke(getItemStroke(row, column));
      g2.fill(p);

代码示例来源:origin: kevin-wayne/algs4

/**
 * Draws a filled rectangle of the specified size, centered at (<em>x</em>, <em>y</em>).
 *
 * @param  x the <em>x</em>-coordinate of the center of the rectangle
 * @param  y the <em>y</em>-coordinate of the center of the rectangle
 * @param  halfWidth one half the width of the rectangle
 * @param  halfHeight one half the height of the rectangle
 * @throws IllegalArgumentException if either {@code halfWidth} or {@code halfHeight} is negative
 */
public static void filledRectangle(double x, double y, double halfWidth, double halfHeight) {
  if (!(halfWidth  >= 0)) throw new IllegalArgumentException("half width must be nonnegative");
  if (!(halfHeight >= 0)) throw new IllegalArgumentException("half height must be nonnegative");
  double xs = scaleX(x);
  double ys = scaleY(y);
  double ws = factorX(2*halfWidth);
  double hs = factorY(2*halfHeight);
  if (ws <= 1 && hs <= 1) pixel(x, y);
  else offscreen.fill(new Rectangle2D.Double(xs - ws/2, ys - hs/2, ws, hs));
  draw();
}

代码示例来源:origin: stackoverflow.com

Rectangle2D rect = new Rectangle2D.Double(x, y, width, height);
g2d.draw(rect);
g2d.draw(line);
for (Point2D p : ps) {
  if (p != null) {
    g2d.fill(new Ellipse2D.Double(p.getX() - 4, p.getY() - 4, 8, 8));

代码示例来源:origin: runelite/runelite

private void renderTargetOverlay(Graphics2D graphics, NPC actor, Color color)
  {
    Polygon objectClickbox = actor.getConvexHull();
    if (objectClickbox != null)
    {
      graphics.setColor(color);
      graphics.setStroke(new BasicStroke(2));
      graphics.draw(objectClickbox);
      graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20));
      graphics.fill(objectClickbox);
    }
  }
}

相关文章

Graphics2D类方法