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

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

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

Graphics2D.setClip介绍

暂无

代码示例

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

Shape clipOld = graphics.getClip();
if (isClipped) graphics.clip(anchor.getBounds2D());
graphics.drawRenderedImage(img, at);
graphics.setClip(clipOld);

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

@Override
public void paint(Graphics2D g) {
 Rectangle2D bounds = getBounds();
 // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
 // g.setColor(Color.red);
 // g.draw(bounds);
 // if the area to draw a chart on is so small, don't even bother
 if (bounds.getWidth() < 30) {
  return;
 }
 java.awt.Shape saveClip = g.getClip();
 // this is for preventing the series to be drawn outside the plot area if min and max is
 // overridden to fall inside the data range
 g.setClip(bounds.createIntersection(bounds));
 chart.toolTips.prepare(g);
 doPaint(g);
 chart.toolTips.paint(g);
 g.setClip(saveClip);
}

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

Color color = graphics.getColor();
Stroke stroke = graphics.getStroke();
Shape clip = graphics.getClip();
graphics.setClip(graphics.getDeviceConfiguration().getBounds());
graphics.setColor(Color.cyan);
graphics.setStroke(new BasicStroke(.5f));
graphics.setClip(clip);

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

Shape oldClip = graphics.getClip();
try {
  paintGraphicFill(graphics, shape, ps2d.getGraphicFill(), scale);
} finally {
  graphics.setClip(oldClip);

代码示例来源:origin: org.jclarion/clarion-runtime

@Override
public void clip(int x1, int y1, int width, int height) {
  clipHist.push(g2d.getClip());
  g2d.setClip(x1,y1,width,height);
}

代码示例来源:origin: gurkenlabs/litiengine

public void renderEntities(final Graphics2D g, final Collection<? extends IEntity> entities, final boolean sort, final Shape clip) {
 // set render shape according to the vision
 final Shape oldClip = g.getClip();
 if (clip != null) {
  g.setClip(clip);
 }
 this.renderEntities(g, entities, sort);
 g.setClip(oldClip);
}

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

public void paintComponent( Graphics g ) {
    Graphics2D gx = (Graphics2D) g;
    Shape old = gx.getClip();
    gx.rotate(-Math.toRadians(45), getWidth()/2, getHeight()/2);
    gx.setClip(old);
    super.paintComponent(gx);

  }
  public void setRotation( int angle ) { this.angle = angle; }
}
}

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

@Override
public void paintComponent(final Graphics g) {
  super.paintComponent(g);
  Graphics2D gImg = (Graphics2D) g;
  Shape oldClip= gImg.getClip();
  Polygon shape = new Polygon(
    new int[] {  0, 100, 100, 50,   0},
    new int[] {200, 200, 100, 50, 100}, 5);
  gImg.setClip(shape);
  gImg.setColor(new Color(255, 0, 0, 50));
  gImg.fill(shape);
  gImg.setClip(oldClip);
}

代码示例来源:origin: gurkenlabs/litiengine

public void render(final Graphics2D g, final Collection<? extends IRenderable> renderables, final Shape clip) {
 // set render shape according to the vision
 final Shape oldClip = g.getClip();
 g.setClip(clip);
 renderables.forEach(r -> r.render(g));
 g.setClip(oldClip);
}

代码示例来源:origin: lbalazscs/Pixelitor

public DragDisplay(Graphics2D g, int bgWidth) {
  this.g = g;
  origComposite = g.getComposite();
  origStroke = g.getStroke();
  origClip = g.getClip();
  this.bgWidth = bgWidth;
  g.setStroke(BG_STROKE);
  g.setClip(null);
}

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

protected void paintComponent(Graphics g) {
  Graphics2D g2 = (Graphics2D)g;
  g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  AffineTransform aT = g2.getTransform();
  Shape oldshape = g2.getClip();

  g2.rotate(Math.toRadians(300));
  super.paintComponent(g);

  g2.setTransform(aT);
  g2.setClip(oldshape);
}

代码示例来源:origin: robo-code/robocode

private void drawBorderEdge(Graphics2D g) {
  final Shape savedClip = g.getClip();
  g.setClip(null);
  g.setColor(Color.RED);
  g.drawRect(-1, -1, battleField.getWidth() + 2, battleField.getHeight() + 2);
  g.setClip(savedClip);
}

代码示例来源:origin: com.jtattoo/JTattoo

public static void fillComponent(Graphics g, Component c, int x, int y, int w, int h) {
    Graphics2D g2D = (Graphics2D) g;
    Shape savedClip = g2D.getClip();
    Area clipArea = new Area(new Rectangle2D.Double(x, y, w, h));
    if (savedClip != null) {
      clipArea.intersect(new Area(savedClip));
    }
    g2D.setClip(clipArea);
    fillComponent(g, c);
    g2D.setClip(savedClip);
  }
}

代码示例来源:origin: senbox-org/snap-desktop

private void drawHistogramPane(Graphics2D g2d) {
  Shape oldClip = g2d.getClip();
  g2d.setClip(histoRect.x - 1, histoRect.y - 1, histoRect.width + 2, histoRect.height + 2);
  drawHistogram(g2d);
  drawGradationCurve(g2d);
  drawHistogramBorder(g2d);
  g2d.setClip(oldClip);
}

代码示例来源:origin: bcdev/beam

private void drawHistogramPane(Graphics2D g2d) {
  Shape oldClip = g2d.getClip();
  g2d.setClip(histoRect.x - 1, histoRect.y - 1, histoRect.width + 2, histoRect.height + 2);
  drawHistogram(g2d);
  drawGradationCurve(g2d);
  drawHistogramBorder(g2d);
  g2d.setClip(oldClip);
}

代码示例来源:origin: org.apache.pivot/pivot-wtk

@Override
public Graphics2D prepare(Component component, Graphics2D graphicsArgument) {
  this.graphics = graphicsArgument;
  int width = component.getWidth();
  int height = component.getHeight();
  if (bufferedImage == null
    || bufferedImage.getWidth() != width
    || bufferedImage.getHeight() != height) {
    bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  }
  bufferedImageGraphics = bufferedImage.createGraphics();
  bufferedImageGraphics.setClip(graphicsArgument.getClip());
  return bufferedImageGraphics;
}

代码示例来源:origin: com.barchart.pivot/pivot-wtk

@Override
public Graphics2D prepare(Component component, Graphics2D graphics) {
  this.graphics = graphics;
  int width = component.getWidth();
  int height = component.getHeight();
  if (bufferedImage == null
    || bufferedImage.getWidth() != width
    || bufferedImage.getHeight() != height) {
    bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  }
  bufferedImageGraphics = bufferedImage.createGraphics();
  bufferedImageGraphics.setClip(graphics.getClip());
  return bufferedImageGraphics;
}

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

private void highlightEditor(final Graphics2D g2) {
  final Component editor = getComponent(0);
  if(editor instanceof NodeView)
    return;
  final java.awt.Shape oldClip = g2.getClip();
  try{
    g2.setClip(editor.getX(), editor.getY(), editor.getWidth(), editor.getHeight());
    super.paintChildren(g2);
  }
  finally{
    g2.setClip(oldClip);
  }
}

相关文章

Graphics2D类方法