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

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

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

Graphics2D.setTransform介绍

暂无

代码示例

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

/**
 * Draws the glyph to the given image, upscaled by a factor of {@link #scale}.
 * 
 * @param image the image to draw to
 * @param glyph the glyph to draw
 */
private void drawGlyph(BufferedImage image, Glyph glyph) {
  Graphics2D inputG = (Graphics2D) image.getGraphics();
  inputG.setTransform(AffineTransform.getScaleInstance(scale, scale));
  // We don't really want anti-aliasing (we'll discard it anyway),
  // but accurate positioning might improve the result slightly
  inputG.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  inputG.setColor(Color.WHITE);
  inputG.fill(glyph.getShape());
}

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

public void setTransform( float translationX, float translationY, int shadowsize, float magnification ) {
 AffineTransform transform = new AffineTransform();
 transform.translate( translationX + shadowsize * magnification, translationY + shadowsize * magnification );
 transform.scale( magnification, magnification );
 gc.setTransform( transform );
}

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

public void setTransform( float translationX, float translationY, int shadowsize, float magnification ) {
 // PDI-9953 - always use original GC's transform.
 AffineTransform transform = (AffineTransform) originalTransform.clone();
 transform.translate( translationX + shadowsize * magnification, translationY + shadowsize * magnification );
 transform.scale( magnification, magnification );
 gc.setTransform( transform );
}

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

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: geotools/geotools

public void testAutoWrapLocalTransform() throws Exception {
  Style style = RendererBaseTest.loadStyle(this, "textWrapEnabled.sld");
  MapContent mc = new MapContent();
  mc.getViewport().setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
  mc.addLayer(new FeatureLayer(fs, style));
  StreamingRenderer renderer = new StreamingRenderer();
  renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON));
  renderer.setMapContent(mc);
  int SIZE = 300;
  final BufferedImage image = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = (Graphics2D) image.getGraphics();
  g.setColor(Color.white);
  g.fillRect(0, 0, SIZE, SIZE);
  g.setTransform(
      new AffineTransform(
          1.1,
          Math.sin(Math.toRadians(15)),
          -Math.sin(Math.toRadians(15)),
          1.1,
          15,
          20));
  renderer.paint(g, new Rectangle(SIZE, SIZE), bounds);
  mc.dispose();
  renderer.getMapContent().dispose();
  String refPath =
      "./src/test/resources/org/geotools/renderer/lite/test-data/textWrapEnabledLocalTransform.png";
  ImageAssert.assertEquals(new File(refPath), image, 3000);
}

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

public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform tmp = g2d.getTransform();
    Object oldInterpolation = g2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
    if (oldInterpolation == null) {
      oldInterpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
    }
    try {
      AffineTransform at = new AffineTransform(tmp);
      at.concatenate(this.at);
      g2d.setTransform(at);
      g2d.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      icon.paintIcon(c, g2d, 0, 0);
    } finally {
      g2d.setTransform(tmp);
      g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolation);
    }
  }
}

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

public static BufferedImage process(BufferedImage im) {
  Log.info("Rotation");
  final BufferedImage newIm = new BufferedImage(im.getHeight(), im.getWidth(), BufferedImage.TYPE_INT_RGB);
  final Graphics2D g2d = newIm.createGraphics();
  final AffineTransform at = new AffineTransform(0, 1, 1, 0, 0, 0);
  at.concatenate(new AffineTransform(-1, 0, 0, 1, im.getWidth(), 0));
  g2d.setTransform(at);
  g2d.drawImage(im, 0, 0, null);
  g2d.dispose();
  return newIm;
}

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

Graphics2D g2d = (Graphics2D) g.create();
AffineTransform at = g2d.getTransform();
at.translate(originX, originY);
g2d.setTransform(at);
g2d.scale(scale, scale);
g2d.rotate(Math.toRadians(angle), 0, 0);
g2d.fillRect(xOffset, yOffset, rectWidth, rectHeight);
g2d.dispose();

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

/**
 * Draws the glyph to the given image, upscaled by a factor of {@link #scale}.
 * 
 * @param image the image to draw to
 * @param glyph the glyph to draw
 */
private void drawGlyph(BufferedImage image, Glyph glyph) {
  Graphics2D inputG = (Graphics2D) image.getGraphics();
  inputG.setTransform(AffineTransform.getScaleInstance(scale, scale));
  // We don't really want anti-aliasing (we'll discard it anyway),
  // but accurate positioning might improve the result slightly
  inputG.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  inputG.setColor(Color.WHITE);
  inputG.fill(glyph.getShape());
}

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

final BufferedImage image = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) image.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, SIZE, SIZE);
g.setTransform(
    new AffineTransform(
        1.1,
        Math.sin(Math.toRadians(15)),

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

Rectangle r = new Rectangle(x, y, delegateIcon.getIconWidth(), delegateIcon.getIconHeight());
g2.setClip(r);
AffineTransform original = g2.getTransform();
AffineTransform at = new AffineTransform();
at.concatenate(original);
at.rotate(Math.toRadians( angleInDegrees ), x + cWidth, y + cHeight);
g2.setTransform(at);
delegateIcon.paintIcon(c, g2, x, y);
g2.setTransform(original);
rotatingTimer.start();

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

Font font = graphics.getFont();
AffineTransform oldTr = graphics.getTransform();
graphics.setTransform(oldTr);

代码示例来源:origin: nguyenq/tess4j

g2.fillRect(0, 0, bi.getWidth(), bi.getHeight());
AffineTransform at = new AffineTransform();
at.rotate(theta, cx, cy);
g2.setTransform(at);
g2.drawImage(image, -minX, -minY, null);
g2.dispose();

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

相关文章

Graphics2D类方法