本文整理了Java中java.awt.Graphics2D.transform()
方法的一些代码示例,展示了Graphics2D.transform()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics2D.transform()
方法的具体详情如下:
包路径:java.awt.Graphics2D
类名称:Graphics2D
方法名:transform
暂无
代码示例来源: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: RaiMan/SikuliX2
@Override
public void paintComponent(Graphics g){
Graphics2D g2d = (Graphics2D) g;
Stroke pen = new BasicStroke(stroke);
g2d.setStroke(pen);
g2d.setColor(colorFront);
GeneralPath polyline = new GeneralPath();
polyline.moveTo(0,0);
polyline.lineTo(5,5);
polyline.lineTo(5,length/2-6);
polyline.lineTo(8,length/2);
polyline.lineTo(5,length/2+6);
polyline.lineTo(5,length-5);
polyline.lineTo(0,length);
AffineTransform rat = new AffineTransform();
if (direction == DIRECTION_EAST){
rat.translate(thickness,length);
rat.rotate(Math.PI);
} else if (direction == DIRECTION_SOUTH){
rat.translate(0,thickness);
rat.rotate(-Math.PI/2);
} else if (direction == DIRECTION_NORTH){
rat.translate(length,0);
rat.rotate(Math.PI/2);
}
g2d.transform(rat);
g2d.draw(polyline);
super.paintComponent(g);
}
}
代码示例来源:origin: knowm/XChart
void paintSeriesText(
Graphics2D g,
Map<String, Rectangle2D> seriesTextBounds,
int markerSize,
double x,
double starty) {
g.setColor(chart.getStyler().getChartFontColor());
g.setFont(chart.getStyler().getLegendFont());
double multiLineOffset = 0.0;
for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) {
double height = entry.getValue().getHeight();
double centerOffsetY = (Math.max(markerSize, height) - height) / 2.0;
FontRenderContext frc = g.getFontRenderContext();
TextLayout tl = new TextLayout(entry.getKey(), chart.getStyler().getLegendFont(), frc);
Shape shape = tl.getOutline(null);
AffineTransform orig = g.getTransform();
AffineTransform at = new AffineTransform();
at.translate(x, starty + height + centerOffsetY + multiLineOffset);
g.transform(at);
g.fill(shape);
g.setTransform(orig);
// // debug box
// Rectangle2D boundsTemp = new Rectangle2D.Double(x, starty + centerOffsetY,
// entry.getValue().getWidth(), height);
// g.setColor(Color.blue);
// g.draw(boundsTemp);
multiLineOffset += height + MULTI_LINE_SPACE;
}
}
代码示例来源:origin: robo-code/robocode
private void paintRobocodeLogo(Graphics2D g) {
setBackground(Color.BLACK);
g.clearRect(0, 0, getWidth(), getHeight());
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.transform(AffineTransform.getTranslateInstance((getWidth() - 320) / 2.0, (getHeight() - 46) / 2.0));
g.setColor(new Color(0, 0x40, 0));
g.fill(robocodeTextPath);
Font font = new Font("Dialog", Font.BOLD, 14);
int width = g.getFontMetrics(font).stringWidth(ROBOCODE_SLOGAN);
g.setTransform(new AffineTransform());
g.setFont(font);
g.setColor(new Color(0, 0x50, 0));
g.drawString(ROBOCODE_SLOGAN, (float) ((getWidth() - width) / 2.0), (float) (getHeight() / 2.0 + 50));
}
代码示例来源:origin: org.piccolo2d/piccolo2d-core
/**
* Pushed the provided transform onto the transform stack if it is not null.
*
* @param transform will be pushed onto the transform stack if not null
*/
public void pushTransform(final PAffineTransform transform) {
if (transform != null) {
final Rectangle2D newLocalClip = (Rectangle2D) getLocalClip().clone();
transform.inverseTransform(newLocalClip, newLocalClip);
transformStack.push(graphics.getTransform());
localClipStack.push(newLocalClip);
graphics.transform(transform);
}
}
代码示例来源:origin: knowm/XChart
g.setColor(styler.getChartFontColor());
g.setFont(styler.getToolTipFont());
AffineTransform orig = g.getTransform();
AffineTransform at = new AffineTransform();
at.translate(x + MARGIN - 1, y + MARGIN - 1 + halfHeight);
g.transform(at);
g.fill(shape);
g.setTransform(orig);
代码示例来源:origin: nodebox/nodebox
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
// Draw background
g2.setColor(Theme.NETWORK_BACKGROUND_COLOR);
g2.fill(g.getClipBounds());
// Paint the grid
// (The grid is not really affected by the view transform)
paintGrid(g2);
// Set the view transform
AffineTransform originalTransform = g2.getTransform();
g2.transform(getViewTransform());
paintNodes(g2);
paintConnections(g2);
paintCurrentConnection(g2);
paintPortTooltip(g2);
paintDragSelection(g2);
paintCommentBox(g2);
// Restore original transform
g2.setTransform(originalTransform);
}
代码示例来源:origin: stackoverflow.com
AffineTransform at = new AffineTransform();
at.concatenate(AffineTransform.getScaleInstance(1, -1));
at.concatenate(AffineTransform.getTranslateInstance(0, -image.getHeight()));
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = newImage.createGraphics();
g.transform(at);
g.drawImage(image, 0, 0, null);
g.dispose();
代码示例来源:origin: knowm/XChart
private void paintSum(Graphics2D g, Rectangle2D pieBounds, double total) {
// draw total value if visible
if (pieStyler.isSumVisible()) {
SumFormatter sumFormatter = pieStyler.getSumFormatter();
String annotation = sumFormatter.format(total);
TextLayout textLayout =
new TextLayout(
annotation, pieStyler.getSumFont(), new FontRenderContext(null, true, false));
Shape shape = textLayout.getOutline(null);
g.setColor(pieStyler.getChartFontColor());
// compute center
Rectangle2D annotationRectangle = textLayout.getBounds();
double xCenter =
pieBounds.getX() + pieBounds.getWidth() / 2 - annotationRectangle.getWidth() / 2;
double yCenter =
pieBounds.getY() + pieBounds.getHeight() / 2 + annotationRectangle.getHeight() / 2;
// set text
AffineTransform orig = g.getTransform();
AffineTransform at = new AffineTransform();
at.translate(xCenter, yCenter);
g.transform(at);
g.fill(shape);
g.setTransform(orig);
}
}
}
代码示例来源:origin: nodebox/nodebox
@Override
public void paintComponent(Graphics g) {
if (!viewPositioned) {
setViewPosition(getWidth() / 2.0, getHeight() / 2.0);
viewPositioned = true;
}
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
// Draw background
g2.setColor(getBackground());
g2.fill(g.getClipBounds());
// Set the view transform
AffineTransform originalTransform = g2.getTransform();
g2.transform(getViewTransform());
paintBounds(g2);
paintObjects(g2);
paintHandle(g2);
paintPoints(g2);
paintPointNumbers(g2);
// Restore original transform
g2.setClip(null);
g2.setTransform(originalTransform);
g2.setStroke(new BasicStroke(1));
paintOrigin(g2);
}
代码示例来源:origin: playn/playn
@Override
public Canvas transform(float m11, float m12, float m21, float m22, float dx, float dy) {
g2d.transform(new AffineTransform(m11, m12, m21, m22, dx, dy));
return this;
}
代码示例来源:origin: knowm/XChart
AffineTransform orig = g.getTransform();
AffineTransform at = new AffineTransform();
g.transform(at);
g.fill(shape);
g.setTransform(orig);
代码示例来源:origin: com.barchart.kitfox/kitfox-svg-core
public void render(Graphics2D g) throws SVGException
{
AffineTransform oldXform = g.getTransform();
g.transform(viewXform);
super.render(g);
g.setTransform(oldXform);
}
代码示例来源:origin: com.googlecode.playn/playn-java
@Override
public Canvas transform(float m11, float m12, float m21, float m22, float dx, float dy) {
gfx.transform(new AffineTransform(m11, m12, m21, m22, dx, dy));
return this;
}
代码示例来源:origin: knowm/XChart
Shape shape = nonRotatedTextLayout.getOutline(rot);
AffineTransform orig = g.getTransform();
AffineTransform at = new AffineTransform();
g.transform(at);
g.fill(shape);
g.setTransform(orig);
AffineTransform orig = g.getTransform();
AffineTransform at = new AffineTransform();
at.translate((float) xOffset, (float) (yOffset - rectangle.getY()));
g.transform(at);
g.fill(shape);
g.setTransform(orig);
代码示例来源:origin: guru.nidi.com.kitfox/svgSalamander
@Override
public void render(Graphics2D g) throws SVGException
{
AffineTransform oldXform = g.getTransform();
g.transform(markerXform);
super.render(g);
g.setTransform(oldXform);
}
代码示例来源:origin: stackoverflow.com
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
if(zoomer==true){
at = new AffineTransform();
at.scale(zoomFactor,zoomFactor);
zoomer=false;
}
g2.transform(at);
代码示例来源:origin: knowm/XChart
AffineTransform orig = g.getTransform();
AffineTransform at = new AffineTransform();
at.translate(xOffset, yOffset);
g.transform(at);
g.fill(shape);
g.setTransform(orig);
代码示例来源:origin: com.metsci.ext.com.kitfox.svg/svg-salamander
public void render(Graphics2D g) throws SVGException
{
AffineTransform oldXform = g.getTransform();
g.transform(viewXform);
super.render(g);
g.setTransform(oldXform);
}
代码示例来源:origin: threerings/playn
@Override
public Canvas transform(float m11, float m12, float m21, float m22, float dx, float dy) {
gfx.transform(new AffineTransform(m11, m12, m21, m22, dx, dy));
return this;
}
内容来源于网络,如有侵权,请联系作者删除!