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

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

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

Graphics2D.getStroke介绍

[英]Returns the current Stroke in the Graphics2D context.
[中]返回Graphics2D上下文中的当前Stroke

代码示例

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

Graphics2D g2;
double thickness = 2;
Stroke oldStroke = g2.getStroke();
g2.setStroke(new BasicStroke(thickness));
g2.drawRect(x, y, width, height);
g2.setStroke(oldStroke);

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

private void drawProgressArc(Graphics2D graphics, int x, int y, int w, int h, double radiusStart, double radiusEnd, int strokeWidth, Color color)
{
  Stroke stroke = graphics.getStroke();
  graphics.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
  graphics.setColor(color);
  graphics.draw(new Arc2D.Double(
    x, y,
    w, h,
    radiusStart, radiusEnd,
    Arc2D.OPEN));
  graphics.setStroke(stroke);
}

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

public static void renderPolygon(Graphics2D graphics, Polygon poly, Color color)
{
  graphics.setColor(color);
  final Stroke originalStroke = graphics.getStroke();
  graphics.setStroke(new BasicStroke(2));
  graphics.drawPolygon(poly);
  graphics.setColor(new Color(0, 0, 0, 50));
  graphics.fillPolygon(poly);
  graphics.setStroke(originalStroke);
}

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

Stroke oldStroke = g2.getStroke();
g2.setColor(GRAPH_COLOR);
g2.setStroke(GRAPH_STROKE);
for (int i = 0; i < graphPoints.size() - 1; i++) {
  int x1 = graphPoints.get(i).x;
g2.setStroke(oldStroke);      
g2.setColor(GRAPH_POINT_COLOR);
for (int i = 0; i < graphPoints.size(); i++) {

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

g2.drawLine(padding + labelPadding, getHeight() - padding - labelPadding, getWidth() - padding, getHeight() - padding - labelPadding);
Stroke oldStroke = g2.getStroke();
g2.setColor(lineColor);
g2.setStroke(GRAPH_STROKE);
for (int i = 0; i < graphPoints.size() - 1; i++) {
  int x1 = graphPoints.get(i).x;
g2.setStroke(oldStroke);
g2.setColor(pointColor);
for (int i = 0; i < graphPoints.size(); i++) {

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

g.fillRect ( 350, 20, 20, 280 );
g.setStroke ( new BasicStroke ( 20.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL ) );
g.translate ( 0, 60 );
arrow.draw ( g );
g.setStroke ( new BasicStroke ( 20.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER ) );
g.translate ( 0, 100 );
arrow.draw ( g );
g.setStroke ( new BasicStroke ( 20.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND ) );
g.translate ( 0, 100 );
arrow.draw ( g );
float arrowLength = 80.0f;
BasicStroke stroke = ( BasicStroke ) g.getStroke();
float arrowLength = 80.0f;
BasicStroke stroke = ( BasicStroke ) g.getStroke();

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

public void draw(Graphics2D g) {
  if (getPointCount() < 2) return;
  // Since a contour has no fill or stroke information, draw it in black.
  // We save the current color so as not to disrupt the context.
  java.awt.Color savedColor = g.getColor();
  Stroke savedStroke = g.getStroke();
  GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, getPointCount());
  _extendPath(gp);
  g.setColor(java.awt.Color.BLACK);
  g.setStroke(DEFAULT_STROKE);
  g.draw(gp);
  g.setColor(savedColor);
  g.setStroke(savedStroke);
}

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

private void drawStraightLabelLine(
    java.awt.Shape outline, boolean drawingHalo, float thickness, float offset) {
  Rectangle2D bounds = outline.getBounds2D().getBounds();
  double minX = bounds.getMinX();
  double maxX = bounds.getMaxX();
  if ((Math.abs(maxX - minX) < 0.0000001)) {
    // nothing to draw
    return;
  }
  // let's se if we are drawing the halo around the underline line
  if (drawingHalo) {
    // when drawing the halo we assume that the correct halo configuration has been set
    graphics.draw(new Line2D.Double(minX, offset, maxX, offset));
  } else {
    // storing the current stroke and setting the stroke according to the specified
    // thickness
    Stroke currentStroke = graphics.getStroke();
    graphics.setStroke(new BasicStroke(thickness));
    // we draw a line with the same color of the text and a stroke of 2
    graphics.draw(new Line2D.Double(minX, offset, maxX, offset));
    // we need to restore the previous stroke
    graphics.setStroke(currentStroke);
  }
}

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

g2.setPaint(paint);
Stroke stroke = g2.getStroke();
g2.setStroke(new BasicStroke(2.0f));
g2.draw(casing);
g2.setStroke(stroke);
g2.setPaint(paint);
Stroke stroke = g2.getStroke();
g2.setStroke(new BasicStroke(2.0f));
g2.draw(casing);
g2.setStroke(stroke);

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

/**
 * Glyph bounding boxes.
 */
@Override
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, String unicode,
             Vector displacement) throws IOException
{
  // draw glyph
  super.showGlyph(textRenderingMatrix, font, code, unicode, displacement);
  
  // bbox in EM -> user units
  Shape bbox = new Rectangle2D.Float(0, 0, font.getWidth(code) / 1000, 1);
  AffineTransform at = textRenderingMatrix.createAffineTransform();
  bbox = at.createTransformedShape(bbox);
  
  // save
  Graphics2D graphics = getGraphics();
  Color color = graphics.getColor();
  Stroke stroke = graphics.getStroke();
  Shape clip = graphics.getClip();
  // draw
  graphics.setClip(graphics.getDeviceConfiguration().getBounds());
  graphics.setColor(Color.RED);
  graphics.setStroke(new BasicStroke(.5f));
  graphics.draw(bbox);
  // restore
  graphics.setStroke(stroke);
  graphics.setColor(color);
  graphics.setClip(clip);
}

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

} else if (i % 10 == 5) {
    Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{5}, 0);
    Stroke oldstroke = g.getStroke();
    g.setStroke(dashed);
    g.drawLine(0, 200 - 1 - i * height_factor, 400, 200 - 1 - i * height_factor);
    g.setStroke(oldstroke);
} else if (i % 2 == 1) {
  Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{5}, 0);
  Stroke oldstroke = g.getStroke();
  g.setStroke(dashed);
  g.drawLine(0, 200 - 1 - i * height_factor, 400, 200 - 1 - i * height_factor);
  g.setStroke(oldstroke);

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

/**
 * Filled path bounding boxes.
 */
@Override
public void fillPath(int windingRule) throws IOException
{
  // bbox in user units
  Shape bbox = getLinePath().getBounds2D();
  
  // draw path (note that getLinePath() is now reset)
  super.fillPath(windingRule);
  
  // save
  Graphics2D graphics = getGraphics();
  Color color = graphics.getColor();
  Stroke stroke = graphics.getStroke();
  Shape clip = graphics.getClip();
  // draw
  graphics.setClip(graphics.getDeviceConfiguration().getBounds());
  graphics.setColor(Color.GREEN);
  graphics.setStroke(new BasicStroke(.5f));
  graphics.draw(bbox);
  // restore
  graphics.setStroke(stroke);
  graphics.setColor(color);
  graphics.setClip(clip);
}

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

} else {
  Stroke oldStroke = graphics.getStroke();
  try {
    graphics.setStroke(new BasicStroke(lineThickness));
    graphics.setStroke(oldStroke);

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

Stroke stroke = graphics.getStroke();
Shape clip = graphics.getClip();
graphics.setStroke(new BasicStroke(.5f));
graphics.draw(bbox);
graphics.setStroke(stroke);
graphics.setColor(color);
graphics.setClip(clip);

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

RenderingHints.VALUE_ANTIALIAS_ON);
Stroke initStroke = g2.getStroke();
g2.setStroke(DRAWING_LINE_STROKE);
if (mouseState == MouseState.DRAGGING && drawingLine != null) {
  g2.setColor(LINE_DRAWING_COLOR);
g2.setStroke(initStroke);

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

Stroke defaultStroke;
 Graphics2D g2d = (Graphics2D) g.create();
 defaultStroke = g2d.getStroke();
 //
 //do your thing
 //
 //reset by
 g2d.setStroke(defaultStroke);

代码示例来源:origin: jsettlers/settlers-remake

/**
   * Initialize the graphics with the stroke
   */
  private void initGraphics() {
    this.originalStroke = graphics.getStroke();
    graphics.setStroke(new BasicStroke(lineWidth));
  }
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

public void paint (Graphics2D graphics, boolean source) {
  Stroke previousStroke = graphics.getStroke ();
  graphics.setStroke (STROKE);
  graphics.draw (path);
  graphics.setStroke (previousStroke);
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

public void paint (Graphics2D g, Rectangle bounds) {
  Stroke s = g.getStroke ();
  g.setColor (color);
  g.setStroke (stroke);
  g.drawRect (bounds.x, bounds.y, bounds.width - thickness, bounds.height - thickness);
  g.setStroke (s);
}

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

public void paintIcon(Component c, Graphics g, int x, int y) {
  Graphics2D g2 = (Graphics2D) g;
  g2.setColor(Color.BLACK);
  Stroke oldStroke = g2.getStroke();
  g2.setStroke(stroke);
  g2.drawLine(x, y+height / 2, x+width, y+height / 2);
  g2.setStroke(oldStroke);
}

相关文章

Graphics2D类方法