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

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

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

Graphics2D.translate介绍

暂无

代码示例

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

public void apply(Graphics2D g) {
  g.translate(_x0, _y0);
  g.scale(_scale, -_scale);
  
}
}

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

public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
  g = (Graphics2D)g.create();
  g.translate(xDistance, yDistance);
  g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), Math.round(opacity * 255)));
  g.fill(glyph.getShape());
  // Also shadow the outline, if one exists.
  for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) {
    Effect effect = (Effect)iter.next();
    if (effect instanceof OutlineEffect) {
      Composite composite = g.getComposite();
      g.setComposite(AlphaComposite.Src); // Prevent shadow and outline shadow alpha from combining.
      g.setStroke(((OutlineEffect)effect).getStroke());
      g.draw(glyph.getShape());
      g.setComposite(composite);
      break;
    }
  }
  g.dispose();
  if (blurKernelSize > 1 && blurKernelSize < NUM_KERNELS && blurPasses > 0) blur(image);
}

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

gradientHeight = height - 16;
g.translate(gradientX, gradientY);
for (int i = 0, n = colors.size() == 1 ? 1 : colors.size() - 1; i < n; i++) {
  Color color1 = colors.get(i);
g.setColor(Color.black);
g.drawRect(0, 0, gradientWidth, gradientHeight);
  xPoints[2] = x + handleWidth / 2;
  if (i == selectedIndex) {
    g.setColor(colors.get(i));
    g.fillPolygon(xPoints, yPoints, 3);
    g.fillRect(xPoints[1], yPoints[1] + 2, handleWidth + 1, 2);
    g.setColor(Color.black);
g.translate(-gradientX, -gradientY);

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

destination = new BufferedImage((int) w, (int) h, BufferedImage.TYPE_INT_ARGB);
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);
gg.dispose();
g2d.scale(1 / dpiFactor, 1 / dpiFactor);
g2d.drawImage(destination, (int) (bounds.getMinX() * dpiFactor), (int) (bounds.getMinY() * dpiFactor), null);
g2d.setTransform(at);

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

private static BufferedImage createImage(Iterable<?> objects, Visualizer visualizer, Rectangle2D bounds, Color backgroundColor) {
  final int width = (int) Math.round(bounds.getWidth());
  final int height = (int) Math.round(bounds.getHeight());
  BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = img.createGraphics();
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  if (backgroundColor != null) {
    g.setColor(backgroundColor);
    g.fillRect(0, 0, width, height);
  }
  g.translate(-bounds.getX(), -bounds.getY());
  visualizer.draw(g, objects);
  img.flush();
  return img;
}

代码示例来源:origin: looly/hutool

/**
 * 旋转图片为指定角度<br>
 * 来自:http://blog.51cto.com/cping1982/130066
 * 
 * @param degree 旋转角度
 * @return 旋转后的图片
 * @since 3.2.2
 */
public Img rotate(int degree) {
  final BufferedImage image = getValidSrcImg();
  int width = image.getWidth(null);
  int height = image.getHeight(null);
  final Rectangle rectangle = calcRotatedSize(width, height, degree);
  final BufferedImage targetImg = new BufferedImage(rectangle.width, rectangle.height, getTypeInt());
  Graphics2D graphics2d = targetImg.createGraphics();
  // 抗锯齿
  graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  // 从中心旋转
  graphics2d.translate((rectangle.width - width) / 2, (rectangle.height - height) / 2);
  graphics2d.rotate(Math.toRadians(degree), width / 2, height / 2);
  graphics2d.drawImage(image, 0, 0, null);
  graphics2d.dispose();
  this.targetImage = targetImg;
  return this;
}

代码示例来源:origin: jphp-group/jphp

@Signature
public PImage rotate(double angle)
{
  double sin = Math.abs(Math.sin(Math.toRadians(angle))),
      cos = Math.abs(Math.cos(Math.toRadians(angle)));
  int w = image.getWidth(null), h = image.getHeight(null);
  int neww = (int) Math.floor(w*cos + h*sin),
      newh = (int) Math.floor(h*cos + w*sin);
  BufferedImage bimg = new BufferedImage(neww, newh, image.getType());
  Graphics2D g = bimg.createGraphics();
  g.translate((neww-w)/2, (newh-h)/2);
  g.rotate(Math.toRadians(angle), w/2, h/2);
  g.drawRenderedImage(image, null);
  g.dispose();
  this.image = bimg;
  return this;
}

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

super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.translate(this.getWidth() / 2, this.getHeight() / 2);
g2d.rotate(theta);
g2d.translate(-image.getWidth(this) / 2, -image.getHeight(this) / 2);
g2d.drawImage(image, 0, 0, null);
  size, size, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();
g2d.setRenderingHint(
  RenderingHints.KEY_ANTIALIASING,
  RenderingHints.VALUE_ANTIALIAS_ON);

代码示例来源:origin: protegeproject/protege

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
  Graphics2D g2 = (Graphics2D) g.create();
  g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
  g2.setColor(WHITE);
  g2.translate(0, HEIGHT / 2 - DOT_SIZE / 2);
  g2.fillOval(0, 0, DOT_SIZE, DOT_SIZE);
  g2.translate(5, 0);
  g2.fillOval(0, 0, DOT_SIZE, DOT_SIZE);
  g2.translate(5, 0);
  g2.fillOval(0, 0, DOT_SIZE, DOT_SIZE);
}

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

@Override
protected void paintComponent(Graphics g)
{
  super.paintComponent(g);

  //Graphics2D ga = (Graphics2D) g;
  Graphics2D ga =  (Graphics2D)g.create();

  ga.translate(175.0, 125.0); //the mouse coordinates stop displaying with this code
  ga.drawLine(0, 0, 100, 100);

  ga.dispose();
}

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

@Override
public void drawParticlesWireframe(Vec2[] centers, float radius, ParticleColor[] colors,
  int count) {
 Graphics2D g = getGraphics();
 saveState(g);
 transformGraphics(g, zero);
 g.setStroke(stroke);
 for (int i = 0; i < count; i++) {
  Vec2 center = centers[i];
  Color color;
  // No alpha channel, it slows everything down way too much.
  if (colors == null) {
   color = pcolor;
  } else {
   ParticleColor c = colors[i];
   color = new Color(c.r * 1f / 127, c.g * 1f / 127, c.b * 1f / 127, 1);
  }
  AffineTransform old = g.getTransform();
  g.translate(center.x, center.y);
  g.scale(radius, radius);
  g.setColor(color);
  g.draw(circle);
  g.setTransform(old);
 }
 restoreState(g);
}

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

graphics.translate(0, rasterHeight);
  graphics.scale(1, -1);
  graphics.translate(rasterWidth, 0);
  graphics.scale(-1, 1);
graphics.scale(xScale, yScale);
graphics.dispose();

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

protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2 = (Graphics2D)g.create();
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2.translate(100, 150);
  g2.rotate(0.4);
  g2.setPaint(Color.red);

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

protected void paintComponent(Graphics g) {
 super.paintComponent(g);
 Graphics2D g2d = (Graphics2D) g.create();
 //...
 if (direction < 0) {
   g2d.scale(-1, 1);
   g2d.translate(-getWidth(), 0);
 }

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

protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D) g.create();
  g2d.translate(x, y);
  g2d.draw(bounds);

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

graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
    RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
    RenderingHints.VALUE_FRACTIONALMETRICS_ON);
graphics.setColor(Color.black);
graphics.setBackground(Color.white);
graphics.clearRect(0, 0, width, height);
graphics.translate(0, img.getHeight());
graphics.scale(scale, -scale);
page.getContent().visitShapes(renderer);
graphics.dispose();

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

protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  float ex = endX - startX;
  float ey = endY - startY;
  if (ex == 0 && ey == 0) {
    return;
  }
  float length = (float) Math.sqrt(ex * ex + ey * ey);
  float bendPercent = (float) Math.asin(ey / length);
  if (endX > startX) {
    bendPercent = -bendPercent;
  }
  Area arrow = getArrow(length, bendPercent);
  Graphics2D g2d = (Graphics2D) g;
  g2d.translate(startX, startY);
  g2d.rotate(Math.atan2(ey, ex));
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2d.setComposite(composite);
  g2d.setColor(this.color);
  g2d.fill(arrow);
  g2d.setColor(Color.BLACK);
  g2d.draw(arrow);
}

代码示例来源:origin: looly/hutool

/**
 * 旋转图片为指定角度<br>
 * 来自:http://blog.51cto.com/cping1982/130066
 * 
 * @param degree 旋转角度
 * @return 旋转后的图片
 * @since 3.2.2
 */
public Img rotate(int degree) {
  final BufferedImage image = getValidSrcImg();
  int width = image.getWidth(null);
  int height = image.getHeight(null);
  final Rectangle rectangle = calcRotatedSize(width, height, degree);
  final BufferedImage targetImg = new BufferedImage(rectangle.width, rectangle.height, getTypeInt());
  Graphics2D graphics2d = targetImg.createGraphics();
  // 抗锯齿
  graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  // 从中心旋转
  graphics2d.translate((rectangle.width - width) / 2, (rectangle.height - height) / 2);
  graphics2d.rotate(Math.toRadians(degree), width / 2, height / 2);
  graphics2d.drawImage(image, 0, 0, null);
  graphics2d.dispose();
  this.targetImage = targetImg;
  return this;
}

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

gradientHeight = height - 16;
g.translate(gradientX, gradientY);
for (int i = 0, n = colors.size() == 1 ? 1 : colors.size() - 1; i < n; i++) {
  Color color1 = colors.get(i);
g.setColor(Color.black);
g.drawRect(0, 0, gradientWidth, gradientHeight);
  xPoints[2] = x + handleWidth / 2;
  if (i == selectedIndex) {
    g.setColor(colors.get(i));
    g.fillPolygon(xPoints, yPoints, 3);
    g.fillRect(xPoints[1], yPoints[1] + 2, handleWidth + 1, 2);
    g.setColor(Color.black);
g.translate(-gradientX, -gradientY);

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

g.translate((neww-w)/2, (newh-h)/2);
g.rotate(Math.toRadians(amount), w/2, h/2);
g.drawRenderedImage(src, null);
g.dispose();
origDst = dst;
  g2.drawImage(dst, 0, 0, null);
} finally {
  g2.dispose();

相关文章

Graphics2D类方法