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


Java AffineTransform.translate方法代码示例

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


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

示例1: applyTexturePaint

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
private void applyTexturePaint(TexturePaint texturePaint) throws IOException {
	Rectangle2D anchorRect = texturePaint.getAnchorRect();
	PDTilingPattern pattern = new PDTilingPattern();
	pattern.setPaintType(PDTilingPattern.PAINT_COLORED);
	pattern.setTilingType(PDTilingPattern.TILING_CONSTANT_SPACING_FASTER_TILING);

	pattern.setBBox(new PDRectangle((float) anchorRect.getX(), (float) anchorRect.getY(),
			(float) anchorRect.getWidth(), (float) anchorRect.getHeight()));
	pattern.setXStep((float) anchorRect.getWidth());
	pattern.setYStep((float) anchorRect.getHeight());

	AffineTransform patternTransform = new AffineTransform();
	patternTransform.translate(0, anchorRect.getHeight());
	patternTransform.scale(1f, -1f);
	pattern.setMatrix(patternTransform);

	PDAppearanceStream appearance = new PDAppearanceStream(document);
	appearance.setResources(pattern.getResources());
	appearance.setBBox(pattern.getBBox());

	PDPageContentStream imageContentStream = new PDPageContentStream(document, appearance,
			((COSStream) pattern.getCOSObject()).createOutputStream());
	BufferedImage texturePaintImage = texturePaint.getImage();
	PDImageXObject imageXObject = imageEncoder.encodeImage(document, imageContentStream, texturePaintImage);

	float ratioW = (float) ((anchorRect.getWidth()) / texturePaintImage.getWidth());
	float ratioH = (float) ((anchorRect.getHeight()) / texturePaintImage.getHeight());
	float paintHeight = (texturePaintImage.getHeight()) * ratioH;
	imageContentStream.drawImage(imageXObject, (float) anchorRect.getX(), (float) (paintHeight + anchorRect.getY()),
			texturePaintImage.getWidth() * ratioW, -paintHeight);
	imageContentStream.close();

	PDColorSpace patternCS1 = new PDPattern(null, imageXObject.getColorSpace());
	COSName tilingPatternName = resources.add(pattern);
	PDColor patternColor = new PDColor(tilingPatternName, patternCS1);

	contentStream.setNonStrokingColor(patternColor);
	contentStream.setStrokingColor(patternColor);
}
 
开发者ID:rototor,项目名称:pdfbox-graphics2d,代码行数:40,代码来源:PdfBoxGraphics2DPaintApplier.java

示例2: paintComponent

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);


    // Rotate image to horizontal
    AffineTransform at = new AffineTransform();
    at.translate(getWidth() / 2, getHeight() / 2);
    at.rotate(this.getRotationAngle(associatedBoat.getOrientation()));
    at.translate(-image.getWidth()/2, -image.getHeight()/2);


    try {
        Graphics2D g2d = (Graphics2D) g;

        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.getOpacity()));

        g2d.drawImage(this.image,at,null);
    } catch (ClassCastException e) {
        e.printStackTrace();
    }

}
 
开发者ID:arthurdeschamps,项目名称:battleship,代码行数:24,代码来源:BoatImageComponent.java

示例3: drawFiltArea

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Draw a semi-trasparent area that is the filtered area
 * @param g The graphic object
 * @param filteredArea The filtered area
 */
public void drawFiltArea(Graphics2D g, Area filtArea) {
	AffineTransform t = new AffineTransform();
	t.scale(scale / 100, scale / 100);
	AffineTransform t2 = new AffineTransform();
	t2.translate(tran_x, tran_y);

	filtArea.transform(t);
	filtArea.transform(t2);

	Stroke oldStro = g.getStroke();
	Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
	g.setStroke(stroke);

	g.setColor(Color.GRAY);
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
	g.setComposite(alphaComp);

	g.fill(filtArea);
	g.setComposite(oldComp);
	g.setStroke(oldStro);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:28,代码来源:PainterConvex2D.java

示例4: transformHelper

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Returns the transform before being applied to the shape. The transform is affected by all groups this element is
 * contained in.
 * 
 * @param oe The EZElement which to get the affine transform of.
 * @return the final AffineTransform that will be applied to the shape.
 */
public static AffineTransform transformHelper(EZElement oe) {
  AffineTransform af = new AffineTransform();
  ArrayList<EZElement> ancestors = new ArrayList<EZElement>();
  EZElement temp;
  temp = oe;

  while (temp.hasParent()) {
    ancestors.add(temp.getParent());
    temp = temp.getParent();
  }

  for (int i = ancestors.size() - 1; i >= 0; i--) {
    temp = ancestors.get(i);
    af.translate(temp.getXCenter(), temp.getYCenter());
    af.scale(temp.getScale(), temp.getScale());
    af.rotate(Math.toRadians(temp.getRotation()));
  }
  af.translate(oe.getXCenter(), oe.getYCenter());
  af.scale(oe.getScale(), oe.getScale());
  af.rotate(Math.toRadians(oe.getRotation()));
  return af;
}
 
开发者ID:gcalica,项目名称:agar.io,代码行数:30,代码来源:EZ.java

示例5: draw

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public void draw(Graphics g, int x, int y, Component obs, double zoom) {
  if (invisibleToMe()) {
    return;
  }
  else if (invisibleToOthers()) {
    final Graphics2D g2d = (Graphics2D) g;

    if (bgColor != null) {
      g.setColor(bgColor);
      final AffineTransform t = AffineTransform.getScaleInstance(zoom, zoom);
      t.translate(x / zoom, y / zoom);
      g2d.fill(t.createTransformedShape(piece.getShape()));
    }

    final Composite oldComposite = g2d.getComposite();
    g2d.setComposite(
      AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparency)
    );
    piece.draw(g, x, y, obs, zoom);
    g2d.setComposite(oldComposite);
  }
  else {
    piece.draw(g, x, y, obs, zoom);
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:26,代码来源:Hideable.java

示例6: makeRandomAT

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static AffineTransform makeRandomAT() {
    AffineTransform at = new AffineTransform();
    at.scale(Math.random() * -10.0, Math.random() * 100.0);
    at.rotate(Math.random() * Math.PI);
    at.shear(Math.random(), Math.random());
    at.translate(Math.random() * 300.0, Math.random() * -20.0);
    return at;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TestRotateMethods.java

示例7: init

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

示例8: run

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
@Override
public void run() {
    BufferedImage img = new BufferedImage(display.getWidth(), display.getHeight(), BufferedImage.TYPE_INT_RGB);
    for (int y = 0; y < display.getHeight(); y++) {
        for (int x = 0; x < display.getWidth(); x++) {
            int idx = getIndex(x, y);
            int nIdx = 3 * idx;
            int r = ((int) (rgbValues[nIdx++] * 255)); // red component 0...255
            int g = ((int) (rgbValues[nIdx++] * 255)); // green component 0...255
            int b = ((int) (rgbValues[nIdx] * 255)); // blue component 0...255
            int col = (r << 16) | (g << 8) | b;
            img.setRGB(x, y, col);
        }
    }
    AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
    tx.translate(0, -img.getHeight(null));
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    img = op.filter(img, null);
    SimpleDateFormat sdfDate = new SimpleDateFormat("_yyyy_MM_dd_HH_mm_ss");//dd/MM/yyyy
    Date now = new Date();
    String strDate = sdfDate.format(now);
    try {
        ImageIO.write(img, "png", new File(String.format("%s/ImageCreator%s.png", path, strDate)));
    } catch (IOException ex) {
        log.warning("can not save Image, Error: " + ex.toString());
    }
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:28,代码来源:ImageCreatorSlave.java

示例9: paintArrowButtonBackground

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Paints the background of an arrow button. Arrow buttons are created by
 * some components, such as <code>JScrollBar</code>.
 *
 * @param context SynthContext identifying the <code>JComponent</code> and
 *        <code>Region</code> to paint to
 * @param g <code>Graphics</code> to paint to
 * @param x X coordinate of the area to paint to
 * @param y Y coordinate of the area to paint to
 * @param w Width of the area to paint to
 * @param h Height of the area to paint to
 */
public void paintArrowButtonBackground(SynthContext context,
                                       Graphics g, int x, int y,
                                       int w, int h) {
    if (context.getComponent().getComponentOrientation().isLeftToRight()){
        paintBackground(context, g, x, y, w, h, null);
    } else {
        AffineTransform transform = new AffineTransform();
        transform.translate(x,y);
        transform.scale(-1, 1);
        transform.translate(-w,0);
        paintBackground(context, g, 0, 0, w, h, transform);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:SynthPainterImpl.java

示例10: unrotate

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static BufferedImage unrotate(BufferedImage img, double angle, int origw, int origh, boolean subpixel, Object interpolation) {

		img = rotate(img, 360 - angle, interpolation);

		int startx = (img.getWidth()-origw)/2;
		int starty = (img.getHeight()-origh)/2;

		int extra = (img.getWidth() - origw) >2 ? 1 : 0;

		img = img.getSubimage(startx, starty, origw + extra, origh + extra);

		AffineTransform t = new AffineTransform();

		if(subpixel) {
			double xerr = 0, yerr =0;
			for(int x = 0; x < img.getWidth(); x++)
				xerr += ImageTools.getAlpha(img.getRGB(x, 0));
			for(int y = 0; y < img.getHeight(); y++)
				yerr += ImageTools.getAlpha(img.getRGB(0, y));

			xerr /= (img.getWidth() * 255);
			xerr = 1 - xerr;
			yerr /= (img.getHeight() * 255);
			yerr = 1 - yerr;
			t.translate(-yerr, -xerr);
		}

		BufferedImage ret = new BufferedImage(origw, origh, BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = ret.createGraphics();
		if(interpolation.equals(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR))
			g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
		else
			g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
		g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation);

		g.drawImage(img, t, null);
		g.dispose();

		return ret;
	}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:41,代码来源:ImageTools.java

示例11: paintComboBoxBackground

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Paints the background of a combo box.
 *
 * @param context SynthContext identifying the <code>JComponent</code> and
 *        <code>Region</code> to paint to
 * @param g <code>Graphics</code> to paint to
 * @param x X coordinate of the area to paint to
 * @param y Y coordinate of the area to paint to
 * @param w Width of the area to paint to
 * @param h Height of the area to paint to
 */
public void paintComboBoxBackground(SynthContext context,
                                    Graphics g, int x, int y,
                                    int w, int h) {
    if (context.getComponent().getComponentOrientation().isLeftToRight()){
        paintBackground(context, g, x, y, w, h, null);
    } else {
        AffineTransform transform = new AffineTransform();
        transform.translate(x,y);
        transform.scale(-1, 1);
        transform.translate(-w,0);
        paintBackground(context, g, 0, 0, w, h, transform);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:SynthPainterImpl.java

示例12: paintTextFieldBackground

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * Paints the background of a text field.
 *
 * @param context SynthContext identifying the <code>JComponent</code> and
 *        <code>Region</code> to paint to
 * @param g <code>Graphics</code> to paint to
 * @param x X coordinate of the area to paint to
 * @param y Y coordinate of the area to paint to
 * @param w Width of the area to paint to
 * @param h Height of the area to paint to
 */
public void paintTextFieldBackground(SynthContext context,
                                      Graphics g, int x, int y,
                                      int w, int h) {
    if (context.getComponent().getComponentOrientation().isLeftToRight()){
        paintBackground(context, g, x, y, w, h, null);
    } else {
        AffineTransform transform = new AffineTransform();
        transform.translate(x,y);
        transform.scale(-1, 1);
        transform.translate(-w,0);
        paintBackground(context, g, 0, 0, w, h, transform);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:SynthPainterImpl.java

示例13: readImage

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public static BufferedImage readImage(Path file, int orientation) throws IOException {
    try {
        BufferedImage image = ImageIO.read(file.toFile());
        int width = image.getWidth();
        int height = image.getHeight();

        AffineTransform t = new AffineTransform();

        switch (orientation) {
            case 2: // Flip X
                t.scale(-1.0, 1.0);
                t.translate(-width, 0);
                break;
            case 3: // PI rotation 
                t.translate(width, height);
                t.rotate(Math.PI);
                break;
            case 4: // Flip Y
                t.scale(1.0, -1.0);
                t.translate(0, -height);
                break;
            case 5: // - PI/2 and Flip X
                t.rotate(-Math.PI / 2);
                t.scale(-1.0, 1.0);
                break;
            case 6: // -PI/2 and -width
                t.translate(height, 0);
                t.rotate(Math.PI / 2);
                break;
            case 7: // PI/2 and Flip
                t.scale(-1.0, 1.0);
                t.translate(-height, 0);
                t.translate(0, width);
                t.rotate(3 * Math.PI / 2);
                break;
            case 8: // PI / 2
                t.translate(0, width);
                t.rotate(3 * Math.PI / 2);
                break;
            default:
                return image;
        }

        AffineTransformOp op = new AffineTransformOp(t, AffineTransformOp.TYPE_BICUBIC);

        BufferedImage destinationImage = op.createCompatibleDestImage(image, (image.getType() == BufferedImage.TYPE_BYTE_GRAY) ? image.getColorModel() : null);
        Graphics2D g = destinationImage.createGraphics();
        g.setBackground(Color.WHITE);
        g.clearRect(0, 0, destinationImage.getWidth(), destinationImage.getHeight());
        destinationImage = op.filter(image, destinationImage);
        return destinationImage;
    } catch (IOException ex) {
        throw new IOException(file.toString() + ": " + ex.getMessage(), ex);
    }
}
 
开发者ID:trebonius0,项目名称:Photato,代码行数:56,代码来源:ImageHelper.java

示例14: setRadialGradientPaint

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
/**
 * This method calculates six m** values and a focusX value that
 * are used by the native fragment shader.  These techniques are
 * based on a whitepaper by Daniel Rice on radial gradient performance
 * (attached to the bug report for 6521533).  One can refer to that
 * document for the complete set of formulas and calculations, but
 * the basic goal is to compose a transform that will convert an
 * (x,y) position in device space into a "u" value that represents
 * the relative distance to the gradient focus point.  The resulting
 * value can be used to look up the appropriate color by linearly
 * interpolating between the two nearest colors in the gradient.
 */
private static void setRadialGradientPaint(RenderQueue rq,
                                           SunGraphics2D sg2d,
                                           RadialGradientPaint paint,
                                           boolean useMask)
{
    boolean linear =
        (paint.getColorSpace() == ColorSpaceType.LINEAR_RGB);
    int cycleMethod = paint.getCycleMethod().ordinal();
    float[] fractions = paint.getFractions();
    Color[] colors = paint.getColors();
    int numStops = colors.length;
    int[] pixels = convertToIntArgbPrePixels(colors, linear);
    Point2D center = paint.getCenterPoint();
    Point2D focus = paint.getFocusPoint();
    float radius = paint.getRadius();

    // save original (untransformed) center and focus points
    double cx = center.getX();
    double cy = center.getY();
    double fx = focus.getX();
    double fy = focus.getY();

    // transform from gradient coords to device coords
    AffineTransform at = paint.getTransform();
    at.preConcatenate(sg2d.transform);
    focus = at.transform(focus, focus);

    // transform unit circle to gradient coords; we start with the
    // unit circle (center=(0,0), focus on positive x-axis, radius=1)
    // and then transform into gradient space
    at.translate(cx, cy);
    at.rotate(fx - cx, fy - cy);
    at.scale(radius, radius);

    // invert to get mapping from device coords to unit circle
    try {
        at.invert();
    } catch (Exception e) {
        at.setToScale(0.0, 0.0);
    }
    focus = at.transform(focus, focus);

    // clamp the focus point so that it does not rest on, or outside
    // of, the circumference of the gradient circle
    fx = Math.min(focus.getX(), 0.99);

    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacity(20 + 28 + (numStops*4*2));
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_RADIAL_GRADIENT_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(linear  ? 1 : 0);
    buf.putInt(numStops);
    buf.putInt(cycleMethod);
    buf.putFloat((float)at.getScaleX());
    buf.putFloat((float)at.getShearX());
    buf.putFloat((float)at.getTranslateX());
    buf.putFloat((float)at.getShearY());
    buf.putFloat((float)at.getScaleY());
    buf.putFloat((float)at.getTranslateY());
    buf.putFloat((float)fx);
    buf.put(fractions);
    buf.put(pixels);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:77,代码来源:BufferedPaints.java

示例15: paintToPDF

import java.awt.geom.AffineTransform; //导入方法依赖的package包/类
public void paintToPDF(JEditorPane jep,File file) {
  try {
    jep.setBounds(0, 0, (int) convertToPixels(612 - 58), (int) convertToPixels(792 - 60));

    Document document = new Document();
    FileOutputStream fos = new FileOutputStream(file);
    PdfWriter writer = PdfWriter.getInstance(document, fos);

    document.setPageSize(new com.lowagie.text.Rectangle(612, 792));
    document.open();
    PdfContentByte cb = writer.getDirectContent();

    cb.saveState();
    cb.concatCTM(1, 0, 0, 1, 0, 0);

    DefaultFontMapper mapper = new DefaultFontMapper();
    mapper.insertDirectory("c:/windows/fonts");

    Graphics2D g2 = cb.createGraphics(612, 792, mapper, true, .95f);

    AffineTransform at = new AffineTransform();
    at.translate(convertToPixels(20), convertToPixels(20));
    at.scale(pixelToPoint, pixelToPoint);

    g2.transform(at);

    g2.setColor(Color.WHITE);
    g2.fill(jep.getBounds());

    Rectangle alloc = getVisibleEditorRect(jep);
    jep.getUI().getRootView(jep).paint(g2, alloc);

    g2.setColor(Color.BLACK);
    g2.draw(jep.getBounds());

    g2.dispose();
    cb.restoreState();
    document.close();
    fos.flush();
    fos.close();
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:ksaluja24,项目名称:scratch-bench,代码行数:45,代码来源:MainMenu.java


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