当前位置: 首页>>代码示例>>Java>>正文


Java Graphics2D.transform方法代码示例

本文整理汇总了Java中java.awt.Graphics2D.transform方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.transform方法的具体用法?Java Graphics2D.transform怎么用?Java Graphics2D.transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics2D的用法示例。


在下文中一共展示了Graphics2D.transform方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createBufferedImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Creates and returns a buffered image into which the chart has been drawn.
 *
 * @param imageWidth  the image width.
 * @param imageHeight  the image height.
 * @param drawWidth  the width for drawing the chart (will be scaled to 
 *                   fit image).
 * @param drawHeight  the height for drawing the chart (will be scaled to 
 *                    fit image).
 * @param info  optional object for collection chart dimension and entity 
 *              information.
 *
 * @return A buffered image.
 */
public BufferedImage createBufferedImage(int imageWidth, 
                                         int imageHeight,
                                         double drawWidth, 
                                         double drawHeight, 
                                         ChartRenderingInfo info) {

    BufferedImage image = new BufferedImage(imageWidth, imageHeight, 
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    double scaleX = imageWidth / drawWidth;
    double scaleY = imageHeight / drawHeight;
    AffineTransform st = AffineTransform.getScaleInstance(scaleX, scaleY);
    g2.transform(st);
    draw(g2, new Rectangle2D.Double(0, 0, drawWidth, drawHeight), null, 
            info);
    g2.dispose();
    return image;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:34,代码来源:JFreeChart.java

示例2: createSVGImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static BufferedImage createSVGImage(String filename, int width, int height) throws Exception
{
	File file = new File(filename);
	FileInputStream fis = new FileInputStream(file);
	SVGUniverse universe = new SVGUniverse();
	universe.loadSVG(fis, file.toURI().toString());
	SVGDiagram diagram = universe.getDiagram(file.toURI());
	diagram.setIgnoringClipHeuristic(true);
	BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics2D g = image.createGraphics();
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g.transform(getAffineTransform((int)diagram.getWidth(), (int)diagram.getHeight(), width, height));
	diagram.render(g);
	g.dispose();
	return image;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:17,代码来源:SVGImageFactory.java

示例3: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(Graphics g, Map map) {
  if (drawGhost) {
    final Point p = map.componentCoordinates(getGhostPosition());

    final Graphics2D g2d = (Graphics2D) g.create();
    g2d.transform(
       AffineTransform.getRotateInstance(-PI_180 * tempAngle,
                                         p.x + centerX(),
                                         p.y + centerY()));
    g2d.setComposite(
       AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                         RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         RenderingHints.VALUE_ANTIALIAS_ON);
    piece.draw(g2d, p.x, p.y, map.getView(), map.getZoom());
    g2d.dispose();
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:20,代码来源:FreeRotator.java

示例4: init

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    double theta = Math.toRadians(15);
    double cos = Math.cos(theta);
    double sin = Math.sin(theta);
    double xsize = sin * h + cos * w;
    double ysize = sin * w + cos * h;
    double scale = Math.min(w / xsize, h / ysize);
    xsize *= scale;
    ysize *= scale;
    AffineTransform at = new AffineTransform();
    at.translate((w - xsize) / 2.0, (h - ysize) / 2.0);
    at.translate(sin * h * scale, 0.0);
    at.rotate(theta);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:GraphicsTests.java

示例5: drawArrow

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) {
    Graphics2D g = (Graphics2D) g1.create();

    double dx = x2 - x1, dy = y2 - y1;
    double angle = Math.atan2(dy, dx);
    int len = (int) Math.sqrt(dx*dx + dy*dy);
    AffineTransform at = AffineTransform.getTranslateInstance(x1, y1);
    at.concatenate(AffineTransform.getRotateInstance(angle));
    g.transform(at);

    g.drawLine(0, 0, len, 0);
    g.fillPolygon(new int[] {len+2, len-(ARR_SIZE*2+1), len-(ARR_SIZE*2+1), len+2},
                  new int[] {0, -(ARR_SIZE-1), ARR_SIZE-1, 0}, 4);
}
 
开发者ID:kevingilboy,项目名称:COE1186,代码行数:15,代码来源:TrackRenderWindow.java

示例6: fillTextArea

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Fills the area of text using green solid color.
 */
private static void fillTextArea(final BufferedImage bi,
                                 final AffineTransform tx1,
                                 final AffineTransform tx2) {
    final Graphics2D bg = bi.createGraphics();
    bg.translate(100, 100);
    bg.transform(tx1);
    bg.transform(tx2);
    bg.setColor(Color.GREEN);
    final Font font = bg.getFont().deriveFont(20.0f);
    bg.setFont(font);
    bg.fill(font.getStringBounds(STR, bg.getFontRenderContext()));
    bg.dispose();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:DrawRotatedStringUsingRotatedFont.java

示例7: init

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.translate(0.0, (h - (w*h)/(w + h*0.1)) / 2);
    at.shear(0.1, 0.0);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:GraphicsTests.java

示例8: init

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.translate(1.5, 1.5);
    g2d.transform(at);
    dim.setSize(w-3, h-3);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:GraphicsTests.java

示例9: tlDrawLine

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void tlDrawLine( Graphics2D g2, TextLayout tl,
                                   float baseX, float baseY ) {
    /// ABP - keep track of old tform, restore it later
    AffineTransform oldTx = null;
    oldTx = g2.getTransform();
    g2.translate( baseX, baseY );
    g2.transform( getAffineTransform( g2Transform ) );

    tl.draw( g2, (float) 0, (float) 0 );

    /// ABP - restore old tform
    g2.setTransform ( oldTx );

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:FontPanel.java

示例10: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Paints the component by drawing the chart to fill the entire component, but allowing for the
 * insets (which will be non-zero if a border has been set for this component). To increase
 * performance (at the expense of memory), an off-screen buffer image can be used.
 * 
 * @param g
 *            the graphics device for drawing on.
 */

@Override
public void paintComponent(Graphics g) {
	if (this.chart == null) {
		return;
	}
	Graphics2D g2 = (Graphics2D) g.create();

	// first determine the size of the chart rendering area...
	Dimension size = getSize();
	Insets insets = getInsets();
	Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
			size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom);

	// work out if scaling is required...
	boolean scale = false;
	double drawWidth = available.getWidth();
	double drawHeight = available.getHeight();
	this.scaleX = 1.0;
	this.scaleY = 1.0;

	if (drawWidth < this.minimumDrawWidth) {
		this.scaleX = drawWidth / this.minimumDrawWidth;
		drawWidth = this.minimumDrawWidth;
		scale = true;
	} else if (drawWidth > this.maximumDrawWidth) {
		this.scaleX = drawWidth / this.maximumDrawWidth;
		drawWidth = this.maximumDrawWidth;
		scale = true;
	}

	if (drawHeight < this.minimumDrawHeight) {
		this.scaleY = drawHeight / this.minimumDrawHeight;
		drawHeight = this.minimumDrawHeight;
		scale = true;
	} else if (drawHeight > this.maximumDrawHeight) {
		this.scaleY = drawHeight / this.maximumDrawHeight;
		drawHeight = this.maximumDrawHeight;
		scale = true;
	}

	Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight);
	// redrawing the chart every time...

	AffineTransform saved = g2.getTransform();
	g2.translate(insets.left, insets.top);
	if (scale) {
		AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY);
		g2.transform(st);
	}
	this.chart.draw(g2, chartArea, this.anchor, this.info);
	g2.setTransform(saved);

	Iterator<Overlay> iterator = this.overlays.iterator();
	while (iterator.hasNext()) {
		Overlay overlay = iterator.next();
		overlay.paintOverlay(g2, this);
	}

	// redraw the zoom rectangle (if present) - if useBuffer is false,
	// we use XOR so we can XOR the rectangle away again without redrawing
	// the chart
	drawSelectionRectangle(g2);

	g2.dispose();

	this.anchor = null;
	this.verticalTraceLine = null;
	this.horizontalTraceLine = null;

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:80,代码来源:AbstractChartPanel.java

示例11: drawArrow

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draws an arrow representing a relation
 * @param g
 * @param e1
 * @param e2
 * @param c
 * @param id
 * @param isConditional
 */
private void drawArrow(Graphics2D g, Event e1, Event e2, Color c, String id, boolean isConditional) {
	Tuple<Position, Position> tuple = shortest(e1, e2);
	Position p1 = tuple.f;
	Position p2 = tuple.s;
	relationPos.add(p1); 
	relationPos.add(p2); 
	AffineTransform oldXForm = g.getTransform();
	g.setColor(c);
	int ARR_SIZE = 8;
	Stroke oldS = g.getStroke();
	int strokeSize = ARR_SIZE/4;
	Stroke newS = new BasicStroke(strokeSize);
	g.setStroke(newS);
		
	double dx = p2.x() - p1.x(), dy = p2.y() - p1.y();
	double angle = Math.atan2(dy, dx);
	
	int len = (int) Math.sqrt(dx*dx + dy*dy);
	AffineTransform at = AffineTransform.getTranslateInstance(p1.x(), p1.y());
	at.concatenate(AffineTransform.getRotateInstance(angle));
	g.transform(at);
	Font fontUp = new Font("Times New Roman", Font.BOLD, 18);
	Font fontDw = new Font("Times New Roman", Font.BOLD, -18);
	FontMetrics mUp = g.getFontMetrics(fontUp);
	if (isConditional) {
		if (p1.x() > p2.x()) {
			g.setFont(fontDw);
			g.drawString(id, (len/2), -strokeSize+MARGIN);
		}
		else {
			g.setFont(fontUp);
			g.drawString(id, (len/2)-mUp.stringWidth(id), -strokeSize);
		}
		len -= CIRCLE_RADIUS;
		g.drawLine(0, 0, len-ARR_SIZE, 0);
		g.fillRoundRect(len, -(CIRCLE_RADIUS/2), CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS);
	}
	else {
		if (p1.x() > p2.x()) {
			g.setFont(fontDw);
			g.drawString(id, CIRCLE_RADIUS+(len/2), -strokeSize+MARGIN);
		}
		else {
			g.setFont(fontUp);
			g.drawString(id, CIRCLE_RADIUS+(len/2)-mUp.stringWidth(id), -strokeSize);
		}
		g.drawLine(CIRCLE_RADIUS, 0, len-ARR_SIZE, 0);
		g.fillRoundRect(0, -(CIRCLE_RADIUS/2), CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS);
	}
	g.fillPolygon(new int[] {len, len-ARR_SIZE, len-ARR_SIZE, len},
                    new int[] {0, -ARR_SIZE, ARR_SIZE, 0}, 4);
	//reset
	g.setStroke(oldS);
	g.setTransform(oldXForm);
}
 
开发者ID:tslaats,项目名称:SE2017-Team2,代码行数:65,代码来源:CrDrawing.java

示例12: init

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void init(TestEnvironment env, Result result) {
    // graphics
    graphics = env.getGraphics();

    // text
    String sname = (String)env.getModifier(tscriptList);
    int slen = env.getIntValue(tlengthList);
    text = getString(sname, slen);

    // chars
    chars = text.toCharArray();

    // font
    String fname = (String)env.getModifier(fnameList);
    if ("Physical".equals(fname)) {
        fname = physicalFontNameFor(sname, slen, text);
    }
    int fstyle = env.getIntValue(fstyleList);
    float fsize = ((Float)env.getModifier(fsizeList)).floatValue();
    AffineTransform ftx = (AffineTransform)env.getModifier(ftxList);
    font = new Font(fname, fstyle, (int)fsize);
    if (hasGraphics2D) {
        if (fsize != Math.floor(fsize)) {
            font = font.deriveFont(fsize);
        }
        if (!ftx.isIdentity()) {
            font = font.deriveFont(ftx);
        }
    }

    // graphics
    if (hasGraphics2D) {
        Graphics2D g2d = (Graphics2D)graphics;
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                             env.getModifier(taaList));
        g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                             env.isEnabled(tfmTog)
                             ? RenderingHints.VALUE_FRACTIONALMETRICS_ON
                             : RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             env.isEnabled(gaaTog)
                             ? RenderingHints.VALUE_ANTIALIAS_ON
                             : RenderingHints.VALUE_ANTIALIAS_OFF);
        g2d.transform((AffineTransform)env.getModifier(gtxList));
    }

    // set result
    result.setUnits(text.length());
    result.setUnitName("char");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:51,代码来源:TextTests.java

示例13: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g.create();

    int w = getWidth();
    int h = getHeight();
    g2d.setColor(Color.black);
    g2d.fillRect(0, 0, w, h);

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         antialiasHint);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                         renderHint);

    g2d.transform(transform);
    g2d.setPaint(paint);

    switch (shapeType) {
    default:
    case RECT:
        g2d.fillRect(0, 0, w, h);
        break;

    case ELLIPSE:
        g2d.fillOval(0, 0, w, h);
        break;

    case MULTIPLE:
        g2d.fillRect(0, 0, w/2, h/2);
        g2d.fillOval(w/2, 0, w/2, h/2);
        g2d.drawOval(0, h/2, w/2, h/2);
        g2d.drawLine(0, h/2, w/2, h);
        g2d.drawLine(0, h, w/2, h/2);
        Polygon p = new Polygon();
        p.addPoint(w/2, h);
        p.addPoint(w, h);
        p.addPoint(3*w/4, h/2);
        g2d.fillPolygon(p);
        break;
    }

    switch (paintType) {
    default:
    case BASIC:
    case LINEAR:
        g2d.setColor(Color.white);
        g2d.fillRect(startX-1, startY-1, 2, 2);
        g2d.drawString("1", startX, startY + 12);
        g2d.fillRect(endX-1, endY-1, 2, 2);
        g2d.drawString("2", endX, endY + 12);
        break;

    case RADIAL:
        g2d.setColor(Color.white);
        g2d.fillRect(ctrX-1, ctrY-1, 2, 2);
        g2d.drawString("C", ctrX, ctrY + 12);
        g2d.fillRect(focusX-1, focusY-1, 2, 2);
        g2d.drawString("F", focusX, focusY + 12);
        break;
    }

    g2d.dispose();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:63,代码来源:MultiGradientTest.java


注:本文中的java.awt.Graphics2D.transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。