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

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

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

Graphics2D.getTransform介绍

暂无

代码示例

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

@Override
 protected void render( Graphics2D gc, int centerX, int centerY, int width, int height, double angleRadians ) {
  AffineTransform oldTransform = gc.getTransform();
  try {
   double scaleX = width * 1.0 / bitmap.getWidth();
   double scaleY = height * 1.0 / bitmap.getHeight();

   AffineTransform affineTransform = new AffineTransform( oldTransform );
   if ( centerX != 0 || centerY != 0 ) {
    affineTransform.translate( centerX, centerY );
   }
   affineTransform.scale( scaleX, scaleY );
   if ( angleRadians != 0 ) {
    affineTransform.rotate( angleRadians );
   }
   affineTransform.translate( -bitmap.getWidth() / 2, -bitmap.getHeight() / 2 );

   gc.setTransform( affineTransform );

   gc.drawImage( bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), null );
  } finally {
   gc.setTransform( oldTransform );
  }
 }
}

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

@Override
public void visit(XDGFShape shape, AffineTransform globalTransform,
    int level) {
  AffineTransform savedTr = _graphics.getTransform();
  _graphics.transform(globalTransform);
  drawPath(shape);
  drawText(shape);
  // we're done, undo the transforms
  _graphics.setTransform(savedTr);
}

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

final Graphics2D gg = destination.createGraphics();
gg.scale(dpiFactor, dpiFactor);
gg.translate(deltaShadow - bounds.getMinX(), deltaShadow - bounds.getMinY());
final boolean isLine = shape instanceof Line2D.Double;
if (isLine) {
  gg.setColor(colorLine);
  gg.draw(shape);
} else {
  gg.setColor(color);
  gg.fill(shape);
final AffineTransform at = g2d.getTransform();
g2d.scale(1 / dpiFactor, 1 / dpiFactor);
g2d.drawImage(destination, (int) (bounds.getMinX() * dpiFactor), (int) (bounds.getMinY() * dpiFactor), null);
g2d.setTransform(at);

代码示例来源:origin: prestodb/presto

g.setColor(Color.WHITE);
g.fillRect(0, 0, WIDTH, HEIGHT);
  g.setColor(Color.getHSBColor(relDepth, 1.0f, 0.9f));
  g.fillRect(x1, EXT_PAD, x2 - x1, GRAPH_HEIGHT);
  g.setColor(Color.getHSBColor(relDepth, 1.0f, 0.9f));
  int y1 = HEIGHT * (depth - minDepth) / (maxDepth - minDepth + 1);
  int y2 = HEIGHT * (depth + 1 - minDepth) / (maxDepth - minDepth + 1);
AffineTransform orig = g.getTransform();
g.rotate(-Math.toRadians(90.0), SCALE_WIDTH + EXT_PAD - 5, GRAPH_HEIGHT + EXT_PAD);
g.drawString("Actual:", SCALE_WIDTH + EXT_PAD - 5, GRAPH_HEIGHT + EXT_PAD);
g.setTransform(orig);
g.setTransform(orig);

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

Font font = graphics.getFont();
AffineTransform oldTr = graphics.getTransform();
  graphics.translate(bounds.x, bounds.y);
  graphics.scale(1, -1);
  graphics.translate(0, -bounds.height
      + graphics.getFontMetrics().getMaxCharBounds(graphics)
      .getHeight());
  graphics.translate(-bounds.width, 0);
graphics.setTransform(oldTr);

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

/**
 * Compute the cumulative height occupied by the text
 *
 * @param oldGraphics the graphics context, which properties are to be copied, may be null
 * @return the height in points
 */
public double getTextHeight(Graphics2D oldGraphics) {
  // dry-run in a 1x1 image and return the vertical advance
  BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
  Graphics2D graphics = img.createGraphics();
  if (oldGraphics != null) {
    graphics.addRenderingHints(oldGraphics.getRenderingHints());
    graphics.setTransform(oldGraphics.getTransform());
  }
  DrawFactory.getInstance(graphics).fixFonts(graphics);
  return drawParagraphs(graphics, 0, 0);
}

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

AffineTransform prev = graphics.getTransform();
float yScale = Math.abs(m.getScalingFactorY());
AffineTransform transform = new AffineTransform(xform);
transform.scale(1.0 / xScale, 1.0 / yScale);
graphics.setTransform(transform);
  graphics.translate(0, image.getHeight());
  graphics.scale(1, -1);
  graphics.translate(x * xScale, y * yScale);
graphics.setTransform(prev);

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

/**
 * Draws the page to the requested context.
 * 
 * @param g The graphics context to draw onto.
 * @param pageSize The size of the page to draw.
 * @throws IOException If there is an IO error while drawing the page.
 */
public void drawPage(Graphics g, PDRectangle pageSize) throws IOException
{
  graphics = (Graphics2D) g;
  xform = graphics.getTransform();
  this.pageSize = pageSize;
  setRenderingHints();
  graphics.translate(0, pageSize.getHeight());
  graphics.scale(1, -1);
  // adjust for non-(0,0) crop box
  graphics.translate(-pageSize.getLowerLeftX(), -pageSize.getLowerLeftY());
  processPage(getPage());
  for (PDAnnotation annotation : getPage().getAnnotations(annotationFilter))
  {
    showAnnotation(annotation);
  }
  graphics = null;
}

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

protected void saveTransform(Graphics2D g) {
  assert (savedTransform == null);
  savedTransform = new AffineTransform(g.getTransform());
}

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

Dimension dim = sheet.getSlideShow().getPageSize();
Color whiteTrans = new Color(1f,1f,1f,0f);
graphics.setColor(whiteTrans);
graphics.fillRect(0, 0, (int)dim.getWidth(), (int)dim.getHeight());
graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, new AffineTransform());
  AffineTransform at = graphics.getTransform();
  graphics.setTransform(at);

代码示例来源:origin: youseries/ureport

bgColor="255,255,255";
g.setColor(getColor(bgColor));
g.fillRect(0, 0, width, height);
AffineTransform transform=g.getTransform();
int allRowHeight=0;
int index=0;
  g.setColor(fontColor);
  int x=slash.getX();
  int y=slash.getY();
  g.rotate(Math.toRadians(slash.getDegree()), x, y);
  g.drawString(text, x, y);
  g.setTransform(transform);
  g.setColor(lineColor);
  int h=allRowHeight+rowHeight;
  if(i==(rowNumber+rowSpan-1)){
    g.setColor(fontColor);
    g.drawString(text, x, y);
    g.setTransform(transform);
    index++;
  g.setColor(fontColor);
  g.drawString(text, x, y);
  g.setTransform(transform);
  ColumnDefinition col=columns.get(i-1);
  int colWidth=UnitUtils.pointToPixel(col.getWidth());

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

public void draw(Graphics2D graphics) {
  // the coordinate system of this group of shape
  Rectangle2D interior = getShape().getInteriorAnchor();
  // anchor of this group relative to the parent shape
  Rectangle2D exterior = getShape().getAnchor();
  AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
  AffineTransform tx0 = new AffineTransform(tx);
  double scaleX = interior.getWidth() == 0. ? 1.0 : exterior.getWidth() / interior.getWidth();
  double scaleY = interior.getHeight() == 0. ? 1.0 : exterior.getHeight() / interior.getHeight();
  tx.translate(exterior.getX(), exterior.getY());
  tx.scale(scaleX, scaleY);
  tx.translate(-interior.getX(), -interior.getY());
  DrawFactory drawFact = DrawFactory.getInstance(graphics);
  AffineTransform at2 = graphics.getTransform();
  
  for (Shape<?,?> child : getShape()) {
    // remember the initial transform and restore it after we are done with the drawing
    AffineTransform at = graphics.getTransform();
    graphics.setRenderingHint(Drawable.GSAVE, true);
    Drawable draw = drawFact.getDrawable(child);
    draw.applyTransform(graphics);
    draw.draw(graphics);
    // restore the coordinate system
    graphics.setTransform(at);
    graphics.setRenderingHint(Drawable.GRESTORE, true);
  }
  graphics.setTransform(at2);
  graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0);
}

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

AffineTransform tx = graphics.getTransform();
  final double ax = anchor.getX();
  final double ay = anchor.getY();
  graphics.translate(ax + anchor.getWidth(), ay);
  graphics.scale(-1, 1);
  graphics.translate(-ax, -ay);
  final double cx = anchor.getCenterX();
  final double cy = anchor.getCenterY();
  graphics.translate(cx, cy);
  graphics.rotate(Math.toRadians(textRot));
  graphics.translate(-cx, -cy);
graphics.setTransform(tx);

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

class MyPanel extends JPanel {
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D)g;
    AffineTransform old = g2d.getTransform();
    g2d.rotate(Math.toRadians(degrees));
    //draw shape/image (will be rotated)
    g2d.setTransform(old);
    //things you draw after here will not be rotated
  }
}

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

@Override
public void translate(int scaleX, int scaleY) {
  transformHist.push(g2d.getTransform());
  g2d.translate(scaleX,scaleY);
}

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

int tsy = ts.getY() - INTERACTING_SHIFT;
graphics.setColor(INTERACTING_COLOR);
graphics.drawLine(fsx, fsy, tsx, tsy);
AffineTransform t = new AffineTransform();
t.translate(tsx, tsy);
t.rotate(tsx - fsx, tsy - fsy);
t.rotate(Math.PI / -2);
AffineTransform ot = graphics.getTransform();
graphics.setTransform(t);
graphics.fill(ARROW_HEAD);
graphics.setTransform(ot);

代码示例来源:origin: net.sourceforge.ondex.apps/ovtk2

public void paintIcon(Component c, Graphics g, int x, int y) {
  Graphics2D g2d = (Graphics2D) g.create();
  AffineTransform transform = g2d.getTransform();
  transform.translate((double) width / 2.0 + 1, (double) height / 2.0 + 1);
  g2d.setTransform(transform);
  g2d.setColor(Color.BLUE);
  g2d.fill(shape);
  g2d.dispose();
}

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

public void paint(Graphics2D g, int width, int height, int x, int y) {
    // saves the old transform;
    AffineTransform oldTransform = g.getTransform();
    try {
      if (oldTransform == null) oldTransform = new AffineTransform();

      AffineTransform transform = new AffineTransform(oldTransform);

      // adds scaling to the transform so that we respect the declared size
      transform.translate(x, y);
      transform.scale(width / bounds.getWidth(), height / bounds.getHeight());
      g.setTransform(transform);
      node.paint(g);
    } finally {
      g.setTransform(oldTransform);
    }
  }
}

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

private void drawTile() {
  Graphics2D g2d = (Graphics2D) gr;
  AffineTransform oldTransform = g2d.getTransform(); //new
  g2d.translate(0, 22);
  g2d.drawImage(img, posX, posY, null);
  g2d.setTransform(oldTransform); //new
  System.out.print(posX+" , "+posY);
}

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

protected void setupTransform(Graphics2D g) {
  saveTransform(g);
  AffineTransform trans = g.getTransform();
  trans.concatenate(getTransform().getAffineTransform());
  g.setTransform(trans);
}

相关文章

Graphics2D类方法