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

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

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

Graphics2D.create介绍

暂无

代码示例

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

public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
  g = (Graphics2D)g.create();
  if (stroke != null)
    g.setStroke(stroke);
  else
    g.setStroke(getStroke());
  g.setColor(color);
  g.draw(glyph.getShape());
  g.dispose();
}

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

public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
  g = (Graphics2D)g.create();
  if (stroke != null)
    g.setStroke(stroke);
  else
    g.setStroke(getStroke());
  g.setColor(color);
  g.draw(glyph.getShape());
  g.dispose();
}

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

public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
  g = (Graphics2D)g.create();
  g.translate(xDistance, yDistance);
  g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), Math.round(opacity * 255)));
  g.fill(glyph.getShape());
  // Also shadow the outline, if one exists.
  for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) {
    Effect effect = (Effect)iter.next();
    if (effect instanceof OutlineEffect) {
      Composite composite = g.getComposite();
      g.setComposite(AlphaComposite.Src); // Prevent shadow and outline shadow alpha from combining.
      g.setStroke(((OutlineEffect)effect).getStroke());
      g.draw(glyph.getShape());
      g.setComposite(composite);
      break;
    }
  }
  g.dispose();
  if (blurKernelSize > 1 && blurKernelSize < NUM_KERNELS && blurPasses > 0) blur(image);
}

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

public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
  g = (Graphics2D)g.create();
  g.translate(xDistance, yDistance);
  g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), Math.round(opacity * 255)));
  g.fill(glyph.getShape());
  // Also shadow the outline, if one exists.
  for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) {
    Effect effect = (Effect)iter.next();
    if (effect instanceof OutlineEffect) {
      Composite composite = g.getComposite();
      g.setComposite(AlphaComposite.Src); // Prevent shadow and outline shadow alpha from combining.
      g.setStroke(((OutlineEffect)effect).getStroke());
      g.draw(glyph.getShape());
      g.setComposite(composite);
      break;
    }
  }
  g.dispose();
  if (blurKernelSize > 1 && blurKernelSize < NUM_KERNELS && blurPasses > 0) blur(image);
}

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

// create an AffineTransform 
// and a triangle centered on (0,0) and pointing downward
// somewhere outside Swing's paint loop
AffineTransform tx = new AffineTransform();
Line2D.Double line = new Line2D.Double(0,0,100,100);

Polygon arrowHead = new Polygon();  
arrowHead.addPoint( 0,5);
arrowHead.addPoint( -5, -5);
arrowHead.addPoint( 5,-5);

// [...]
private void drawArrowHead(Graphics2D g2d) {  
  tx.setToIdentity();
  double angle = Math.atan2(line.y2-line.y1, line.x2-line.x1);
  tx.translate(line.x2, line.y2);
  tx.rotate((angle-Math.PI/2d));  

  Graphics2D g = (Graphics2D) g2d.create();
  g.setTransform(tx);   
  g.fill(arrowHead);
  g.dispose();
}

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

private void safeRender(Client client, Overlay overlay, OverlayLayer layer, Graphics2D graphics, Point point)
{
  final Graphics2D subGraphics = (Graphics2D) graphics.create();
  if (!isResizeable && (layer == OverlayLayer.ABOVE_SCENE || layer == OverlayLayer.UNDER_WIDGETS))
  {
    subGraphics.setClip(client.getViewportXOffset(),
      client.getViewportYOffset(),
      client.getViewportWidth(),
      client.getViewportHeight());
  }
  final OverlayPosition position = overlay.getPosition();
  // Set font based on configuration
  if (position == OverlayPosition.DYNAMIC || position == OverlayPosition.DETACHED)
  {
    subGraphics.setFont(runeLiteConfig.fontType().getFont());
  }
  else if (position == OverlayPosition.TOOLTIP)
  {
    subGraphics.setFont(runeLiteConfig.tooltipFontType().getFont());
  }
  else
  {
    subGraphics.setFont(runeLiteConfig.interfaceFontType().getFont());
  }
  subGraphics.translate(point.x, point.y);
  final Dimension dimension = MoreObjects.firstNonNull(overlay.render(subGraphics), new Dimension());
  subGraphics.dispose();
  overlay.setBounds(new Rectangle(point, dimension));
}

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

public Graphics create() {
  return delegate.create();
}

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

public Graphics create(int x, int y, int width, int height) {
  return delegate.create(x, y, width, height);
}

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

private Graphics2D getUnmodifiedHalfContext(Graphics2D g) {
  Graphics2D g2 = (Graphics2D) g.create();
  g2.translate(leftHalf.x, leftHalf.y);
  return g2;
}

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

public void draw(Graphics2D g) {
  Graphics2D gg = (Graphics2D) g.create();
  gg.rotate(angle, rect.x + rect.width/2, rect.y + rect.height/2);
  gg.drawRect(rect.x, rect.y, rect.width, rect.height);
  gg.dispose();

  gg = (Graphics2D) g.create();
  ... other stuff
}

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

private Graphics2D getAftermathHalfContext(Graphics2D g) {
  Graphics2D g2 = (Graphics2D) g.create();
  g2.translate(rightHalf.x, rightHalf.y);
  g2.rotate(Math.PI / 2);
  g2.translate(0, -rightHalf.w);
  return g2;
}

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

private Graphics2D getRightHalfContext(Graphics2D g) {
  Graphics2D g2 = (Graphics2D) g.create();
  g2.translate(rightHalf.x, rightHalf.y);
  g2.rotate(-Math.PI / 2);
  g2.translate(-rightHalf.cw, 0);
  return g2;
}

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

@Override
public Graphics create()
{
  Graphics g = groupG2D.create();
  Graphics a = alphaG2D.create();
  if (g instanceof Graphics2D && a instanceof Graphics2D)
  {
    return new GroupGraphics(groupImage, (Graphics2D)g, groupAlphaImage, (Graphics2D)a);
  }
  throw new UnsupportedOperationException();
}

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

private Graphics2D getLeftHalfContext(Graphics2D g) {
  Graphics2D g2 = (Graphics2D) g.create();
  g2.translate(leftHalf.x, leftHalf.y);
  g2.rotate(-Math.PI / 2);
  g2.translate(-leftHalf.cw, 0);
  return g2;
}

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

private void paintBackground(Graphics2D graphics, AbstractButton b) {
  Graphics2D g = (Graphics2D) graphics.create();
  try {
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
    Color startingColor = look.colors().shadow().brighter().brighter();
    Color endingColor = look.colors().shadow().darker();
    g.setPaint(new GradientPaint(0, 0, startingColor, 0, b.getHeight(), endingColor));
    g.fillRect(1, 1, b.getWidth()-2, b.getHeight()-2);
  } finally {
    g.dispose();
  }
}

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

@Override
public void paint(Graphics g) {
  if (!displayEnabled) {
    return;
  }
  if (!isValid()) {
    super.validate();
  }
  Graphics2D g2d = (Graphics2D) g;
  if (transformAngle < 1) {
    float edgeOffset = (cardWidth + cardXOffset) / 2f;
    g2d.translate(edgeOffset * (1 - transformAngle), 0);
    g2d.scale(transformAngle, 1);
  }
  if (tappedAngle + flippedAngle > 0) {
    g2d = (Graphics2D) g2d.create();
    float edgeOffset = cardWidth / 2f;
    double angle = tappedAngle + (Math.abs(flippedAngle - FLIPPED_ANGLE) < 0.001 ? 0 : flippedAngle);
    g2d.rotate(angle, cardXOffset + edgeOffset, cardYOffset + cardHeight - edgeOffset);
  }
  super.paint(g2d);
}

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

@Override
public void draw(Graphics2D graphics, MapContent map, MapViewport viewport) {
  Graphics2D localGraphics = (Graphics2D) graphics.create();
  localGraphics.setPaint(Color.WHITE);
  localGraphics.fill(SCREEN);
  Rectangle inner =
      new Rectangle(
          SCREEN.x + SCREEN.width / 4,
          SCREEN.y + SCREEN.height / 4,
          SCREEN.width / 2,
          SCREEN.height / 2);
  localGraphics.setPaint(Color.BLACK);
  localGraphics.fill(inner);
}

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

Graphics2D g2 = (Graphics2D) g.create();
g2.translate(xPos, yPos);
g2.scale(scale, scale);

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

ParallelLinesFiller filler = ParallelLinesFiller.fromStipple(rescaledStipple);
    if (filler != null) {
      Graphics2D clippedGraphics = (Graphics2D) graphics.create();
Graphics2D g = (Graphics2D) graphics.create();

代码示例来源:origin: danfickle/openhtmltopdf

@Override
public void drawWithGraphics(float x, float y, float width, float height, OutputDeviceGraphicsDrawer renderer) {
  Graphics2D graphics = (Graphics2D) _graphics.create((int) x, (int) y, (int) width, (int) height);
  renderer.render(graphics);
  graphics.dispose();
}

相关文章

Graphics2D类方法