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

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

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

Graphics2D.setStroke介绍

[英]Sets the Stroke for the Graphics2D context.
[中]为Graphics2D上下文设置Stroke

代码示例

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

public void draw(Graphics2D g2d) {
  g2d.setStroke(new BasicStroke((float) 1.5));
  g2d.draw(curve);
  g2d.setStroke(new BasicStroke());
}

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

/**
 * Sets the radius of the pen to the given size.
 *
 * @param  r the radius of the pen
 * @throws IllegalArgumentException if r is negative
 */
public void setPenRadius(double r) {
  if (r < 0) throw new IllegalArgumentException("pen radius must be positive");
  penRadius = r * DEFAULT_SIZE;
  BasicStroke stroke = new BasicStroke((float) penRadius, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
  // BasicStroke stroke = new BasicStroke((float) penRadius);
  offscreen.setStroke(stroke);
}

代码示例来源: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: 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

g.setColor(Color.white);
g.fillRect(chartX, chartY, chartWidth, chartHeight);
g.setColor(Color.black);
g.drawRect(chartX, chartY, chartWidth, chartHeight);
    int x = (int)(yAxisWidth + chartWidth * percent);
    if (i != 0 && i != xSplit) {
      g.setColor(Color.lightGray);
      g.drawLine(x, chartY + 1, x, chartY + chartHeight);
      g.setColor(Color.black);
g.setColor(Color.blue);
g.setStroke(new BasicStroke(isExpanded ? 3 : 2));
int lastX = -1, lastY = -1;
for (Point point : points) {

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

g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setColor(getRandColor(210, 250));
g.fillRect(0, 0, WIDTH, HEIGHT);
for(int i = 0; i < 20; i++){
  color = getRandColor(120, 200);
  g.setColor(color);
  String rand = String.valueOf(charArray[random.nextInt(charArray.length)]);
  g.drawString(rand, random.nextInt(WIDTH), random.nextInt(HEIGHT));
  g.setColor(color);
g.setColor(color);
BasicStroke bs = new BasicStroke(3);
g.setStroke(bs);
g.draw(curve);

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

antialiasSetting = RenderingHints.VALUE_ANTIALIAS_ON;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasSetting);
g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND));
g2.setStroke(normalStroke);
shapesIt = storageShapes.iterator();
while(shapesIt.hasNext()){
    g2.setStroke(dashStroke);
  else
    g2.setStroke(normalStroke);
  g2.setColor(shape.getStrokeColor());
  g2.draw(path);
      g2.setStroke(dashStroke);
    else
      g2.setStroke(normalStroke);
    g2.draw(path);
g2.setStroke(normalStroke);
shapesIt = pointMarkers.iterator();
while(shapesIt.hasNext()){
    BasicStroke.JOIN_ROUND
   );
  g2.setStroke(debugStroke);

代码示例来源:origin: pentaho/pentaho-kettle

private void drawImage( SwingUniversalImage img, int centerX, int centerY, double angle, int imageSize ) {
 if ( isDrawingPixelatedImages() && img.isBitmap() ) {
  BufferedImage bi =  img.getAsBitmapForSize( imageSize, imageSize, angle );
  int offx = centerX + xOffset - bi.getWidth() / 2;
  int offy = centerY + yOffset - bi.getHeight() / 2;
  for ( int x = 0; x < bi.getWidth( observer ); x++ ) {
   for ( int y = 0; y < bi.getHeight( observer ); y++ ) {
    int rgb = bi.getRGB( x, y );
    gc.setColor( new Color( rgb ) );
    gc.setStroke( new BasicStroke( 1.0f ) );
    gc.drawLine( offx + x, offy + y, offx + x, offy + y );
   }
  }
 } else {
  gc.setBackground( Color.white );
  gc.clearRect( centerX, centerY, imageSize, imageSize );
  img.drawToGraphics( gc, centerX, centerY, imageSize, imageSize, angle );
 }
}

代码示例来源:origin: sarxos/webcam-capture

g2.setRenderingHint(KEY_ANTIALIASING, isAntialiasingEnabled() ? VALUE_ANTIALIAS_ON : VALUE_ANTIALIAS_OFF);
g2.setBackground(Color.BLACK);
g2.fillRect(0, 0, getWidth(), getHeight());
int cy = (getHeight() - 40) / 2;
g2.setStroke(new BasicStroke(2));
g2.setColor(Color.LIGHT_GRAY);
g2.fillRoundRect(cx, cy, 70, 40, 10, 10);
g2.setColor(Color.WHITE);
g2.fillOval(cx + 5, cy + 5, 30, 30);
g2.setColor(Color.LIGHT_GRAY);
g2.fillOval(cx + 10, cy + 10, 20, 20);
g2.setColor(Color.WHITE);
g2.setColor(Color.DARK_GRAY);
g2.setStroke(new BasicStroke(3));
g2.drawLine(0, 0, getWidth(), getHeight());
g2.drawLine(0, getHeight(), getWidth(), 0);
g2.setRenderingHint(KEY_ANTIALIASING, antialiasing);

代码示例来源:origin: pentaho/pentaho-kettle

private void drawImage( SwingUniversalImage img, int locationX, int locationY, int imageSize ) {
 if ( isDrawingPixelatedImages() && img.isBitmap() ) {
  BufferedImage bi = new BufferedImage( imageSize, imageSize, BufferedImage.TYPE_INT_ARGB );
  Graphics2D g2 = (Graphics2D) bi.getGraphics();
  g2.setColor( Color.WHITE );
  g2.fillRect( 0, 0, imageSize, imageSize );
  g2.drawImage( img.getAsBitmapForSize( imageSize, imageSize ), 0, 0, observer );
  g2.dispose();
  for ( int x = 0; x < bi.getWidth( observer ); x++ ) {
   for ( int y = 0; y < bi.getHeight( observer ); y++ ) {
    int rgb = bi.getRGB( x, y );
    gc.setColor( new Color( rgb ) );
    gc.setStroke( new BasicStroke( 1.0f ) );
    gc.drawLine( locationX + xOffset + x, locationY + yOffset + y, locationX + xOffset + x, locationY
     + yOffset + y );
   }
  }
 } else {
  gc.setBackground( Color.white );
  gc.clearRect( locationX, locationY, imageSize, imageSize );
  img.drawToGraphics( gc, locationX, locationY, imageSize, imageSize );
 }
}

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

gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gr.setColor(Color.WHITE);
gr.fillRect(0, 0, image.getWidth(), image.getHeight());
gr.setColor(Color.LIGHT_GRAY);
gr.setStroke(new BasicStroke(1, 0, 0, 1, new float[] {5, 5}, 0));
gr.draw(new Line2D.Double(0, 300, 600, 300));
gr.draw(new Line2D.Double(300, 0, 300, 600));
at.scale(10, -10);
gr.setStroke(new BasicStroke(1));
gr.setColor(Color.LIGHT_GRAY);
gr.draw(new LiteShape(boundsPoly, at, false));
gr.setStroke(new BasicStroke(0.5f));
gr.setColor(Color.BLUE);
gr.draw(new LiteShape(original, at, false));
if (clipped != null) {
  gr.setStroke(new BasicStroke(2));
  if (clipped instanceof Polygon || clipped instanceof MultiPolygon) {
    gr.setColor(Color.LIGHT_GRAY);
    gr.fill(new LiteShape(clipped, at, false));
    gr.setColor(Color.BLUE);

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

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));
  g2d.setStroke(new BasicStroke((float) 1.5));
  g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos);
  g2d.setStroke(new BasicStroke());

代码示例来源:origin: bonnyfone/vectalign

graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  graphics.setColor(shadowColorA);
  graphics.fillRoundRect(
graphics.setColor(getBackground());
graphics.fillRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height);
graphics.setColor(getForeground());
graphics.setStroke(new BasicStroke(strokeSize));
graphics.drawRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height);
graphics.setStroke(new BasicStroke());

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

for (BufferedImage icon : icons)
  graphics.setStroke(new BasicStroke(2));
  graphics.setColor(COLOR_ICON_BACKGROUND);
  graphics.fillOval(
    point.getX() - totalWidth / 2 + currentPosX - bgPadding,
    icon.getHeight() + bgPadding * 2);
  graphics.setColor(COLOR_ICON_BORDER);
  graphics.drawOval(
    point.getX() - totalWidth / 2 + currentPosX - bgPadding,
    null);
  graphics.setColor(COLOR_ICON_BORDER_FILL);
  Arc2D.Double arc = new Arc2D.Double(
    point.getX() - totalWidth / 2 + currentPosX - bgPadding,
      gorilla.getAttacksUntilSwitch()) / DemonicGorilla.ATTACKS_PER_SWITCH,
    Arc2D.OPEN);
  graphics.draw(arc);

代码示例来源:origin: RaiMan/SikuliX2

@Override
  public void paintComponent(Graphics g){
   Dimension d = new Dimension(textBox.width + triangle.width, textBox.height);
   Dimension originalSize = canonicalSize;
   Dimension actualSize = getActualSize();
   float scalex = 1f * actualSize.width / originalSize.width;
   float scaley = 1f * actualSize.height / originalSize.height;
   ((Graphics2D) g).scale(scalex, scaley);
   super.paintComponent(g);
   Graphics2D g2d = (Graphics2D) g;
   g2d.setFont(font);
   g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
      RenderingHints.VALUE_ANTIALIAS_ON));
   g2d.setColor(colorFront);
   g2d.fill(flagShape);
   // draw outline
   Stroke pen = new BasicStroke(1.0F);
   g2d.setStroke(pen);
   g2d.setColor(colorFrame);
   g2d.draw(flagShape);
   g2d.setColor(colorText);
   g2d.drawString(text, textBox.x + PADDING_X,
      textBox.y +  textBox.height - fm.getDescent() - PADDING_Y);
  }
}

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

g2.setPaint(paint);
g2.setStroke(new BasicStroke(3));
g2.draw(arc);
g2.draw(new Rectangle(end_curve_ex, bot_ey, mid_ex - end_curve_ex, 0));
g2.draw(arc3);
g2.draw(new Rectangle(end_mid_ex, bot_ey, mid_ex - end_curve_ex, 0));
g2.draw(arc2);
g2.setStroke(new BasicStroke(1));
g2.setColor(boxColor);

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

private static final Color GRAPH_COLOR = Color.green;
private static final Color GRAPH_POINT_COLOR = new Color(150, 50, 50, 180);
private static final Stroke GRAPH_STROKE = new BasicStroke(3f);
private static final int GRAPH_POINT_WIDTH = 12;
private static final int Y_HATCH_CNT = 10;
 super.paintComponent(g);
 Graphics2D g2 = (Graphics2D)g;
 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 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: FudanNLP/fnlp

public static void printTree(Cluster a,String file) {  
  int depth = getDepth(a);
  
  width =  wunit*(depth+1);
  height = hunit*(depth+1);
  BufferedImage image  = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = image .createGraphics();
  
  g.setColor(new Color(0,0,0)); 
  g.setStroke(new BasicStroke(1)); 
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  Font font = new Font("宋体", Font.BOLD, 20); 
  
  g.setFont(font);   
  
  drawTree(a, g, width/2, 0 , 1);
  //释放对象 
  g.dispose(); 
  // 保存文件    
  try {
    ImageIO.write(image, "png", new File(file));
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  } 
}

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

pointerLength = Math.max(pointerLength, radius);
imageGraphic = image.createGraphics();
imageGraphic.setColor(circleColor);
imageGraphic.fillOval(
    circleCenterX - radius, circleCenterY - radius, radius * 2, radius * 2);
imageGraphic.setColor(wedgeColor);
imageGraphic.fillArc(
    circleCenterX - radius,
    calculateWedgeAngle(pointerDirection, wedgeWidth),
    wedgeWidth * 2);
imageGraphic.setColor(barUncColor);
imageGraphic.fillRect(
    circleCenterX - barUncWidth,
    calculateEndOfPointer(
        circleCenterX, circleCenterY, pointerLength, pointerDirection);
imageGraphic.setStroke(new java.awt.BasicStroke(3));
imageGraphic.setColor(pointerColor);
imageGraphic.draw(
    new java.awt.geom.Line2D.Double(
        circleCenterX, circleCenterY, endPoint[0], endPoint[1]));
imageGraphic.setStroke(new java.awt.BasicStroke(3));
imageGraphic.setColor(barColor);
imageGraphic.draw(
    new java.awt.geom.Line2D.Double(
        circleCenterX, circleCenterY, circleCenterX, circleCenterY - barHeight));

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

@Override
  public Dimension render(Graphics2D graphics)
  {
    int thickness = borderThickness;
    int width = preferredSize.width;
    int height = preferredSize.height;

    //draw the fill
    graphics.setColor(fill);
    graphics.fillRect(thickness, thickness, width - thickness * 2, height - thickness * 2);

    //because the stroke is centered on the rectangle we draw, we need to translate where we draw the rectangle
    //this is to ensure that the rectangle we draw is our preferred size
    int offset = thickness / 2;
    graphics.setColor(color);
    graphics.setStroke(stroke);
    graphics.drawRect(offset, offset, width - thickness, height - thickness);
    return preferredSize;
  }
}

相关文章

Graphics2D类方法