List of usage examples for java.awt.geom AffineTransform translate
public void translate(double tx, double ty)
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static void drawArcTest(Graphics2D g2) { g2.setPaint(Color.GREEN);/*from www .ja v a 2 s. com*/ g2.drawRect(0, 20, 70, 50); g2.setPaint(Color.RED); Path2D path1 = new Path2D.Double(); double[] pts = calculateReferenceArc(90); path1.moveTo(pts[0], pts[1]); path1.curveTo(pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]); AffineTransform t = new AffineTransform(); t.translate(35, 45); t.scale(35, 25); t.rotate(Math.PI / 4); path1.transform(t); g2.draw(path1); Path2D path2 = new Path2D.Double(); path2.moveTo(pts[0], pts[1]); path2.curveTo(pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]); AffineTransform t2 = new AffineTransform(); t2.rotate(3 * Math.PI / 4); t2.scale(35, 25); t2.translate(35, 35); path2.transform(t2); //g2.draw(path2); Path2D arc = new Path2D.Double(); arc.append(path1, false); arc.append(path2, false); //g2.draw(arc); //g2.draw(path1); //g2.transform(t); g2.setPaint(Color.BLUE); g2.drawArc(0, 20, 70, 50, 0, -270); //Arc2D arc2d = new Arc2D.Double(0d, 20d, 70d, 50d, 0d, 90, Arc2D.OPEN); //g2.draw(arc2d); }
From source file:de.mfo.jsurf.grid.RotationGrid.java
public static void saveToPNG(OutputStream os, BufferedImage bufferedImage) throws java.io.IOException { AffineTransform tx = AffineTransform.getScaleInstance(1, -1); tx.translate(0, -bufferedImage.getHeight(null)); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); bufferedImage = op.filter(bufferedImage, null); javax.imageio.ImageIO.write(bufferedImage, "png", os); }
From source file:de.bund.bfr.jung.JungUtils.java
static <V, E> Shape getTransformedEdgeShape(RenderContext<V, E> rc, Layout<V, E> layout, E e) { Graph<V, E> graph = layout.getGraph(); edu.uci.ics.jung.graph.util.Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst();//from www. j a v a 2 s . c o m V v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<V, E>, E>getInstance(graph, e)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v1)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v2))) { return null; } Point2D p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1)); Point2D p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2)); float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); Shape edgeShape = rc.getEdgeShapeTransformer().transform(Context.getInstance(graph, e)); AffineTransform edgeShapeTransform = AffineTransform.getTranslateInstance(x1, y1); if (v1.equals(v2)) { Rectangle2D bounds = rc.getVertexShapeTransformer().transform(v1).getBounds2D(); edgeShapeTransform.scale(bounds.getWidth(), bounds.getHeight()); edgeShapeTransform.translate(0, -edgeShape.getBounds2D().getWidth() / 2); } else { float dx = x2 - x1; float dy = y2 - y1; edgeShapeTransform.rotate(Math.atan2(dy, dx)); edgeShapeTransform.scale(Math.sqrt(dx * dx + dy * dy), 1.0); } return edgeShapeTransform.createTransformedShape(edgeShape); }
From source file:com.mikenimer.familydam.services.photos.ThumbnailService.java
/** * get the right transformation based on the orientation setting in the exif metadata. In case the physical image is actually * stored in a rotated state./*from ww w . j a v a 2 s . c o m*/ * * @param orientation * @param width * @param height * @return */ public static AffineTransform getExifTransformation(int orientation, double width, double height, double scaleW, double scaleH) { AffineTransform t = new AffineTransform(); switch (orientation) { case 1: t.scale(scaleW, scaleH); break; case 2: // Flip X //todo: test & fix t.scale(-scaleW, scaleH); t.translate(-width, 0); break; case 3: // PI rotation t.translate(width, height); t.rotate(Math.PI); t.scale(scaleW, scaleH); break; case 4: // Flip Y //todo: test & fix t.scale(scaleW, -scaleH); t.translate(0, -height); break; case 5: // - PI/2 and Flip X t.rotate(-Math.PI / 2); t.scale(-scaleW, scaleH); break; case 6: // -PI/2 and -width t.translate(height, 0); t.rotate(Math.PI / 2); t.scale(scaleW, scaleH); break; case 7: // PI/2 and Flip //todo:test & fix t.scale(-scaleW, scaleH); 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); t.scale(scaleW, scaleH); break; } return t; }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java
private static Shape createShape(double x, double y, Rectangle2D hotspot) { Area result = new Area(new RoundRectangle2D.Double(hotspot.getX(), hotspot.getY(), hotspot.getWidth(), hotspot.getHeight(), 8, 8)); boolean right = hotspot.getMinX() > x; Polygon po = new Polygon(); po.addPoint(0, 0);/*from w ww . j a va 2s . co m*/ po.addPoint(0, 10); po.addPoint(10, 0); AffineTransform af = new AffineTransform(); if (right) { af.translate(hotspot.getX() - 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(-Math.PI / 4); } else { af.translate(hotspot.getMaxX() + 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(Math.PI * 3 / 4); } Shape shape = af.createTransformedShape(po); result.add(new Area(shape)); return result; }
From source file:com.aimluck.eip.fileupload.util.FileuploadUtils.java
public static AffineTransform getExifTransformation(ImageInformation info) { AffineTransform t = new AffineTransform(); if (info == null) { return t; }/*from w ww.j a v a2s.co m*/ switch (info.orientation) { case 1: break; case 2: // Flip X t.scale(-1.0, 1.0); t.translate(-info.width, 0); break; case 3: // PI rotation t.translate(info.width, info.height); t.rotate(Math.PI); break; case 4: // Flip Y t.scale(1.0, -1.0); t.translate(0, -info.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(info.height, 0); t.rotate(Math.PI / 2); break; case 7: // PI/2 and Flip t.scale(-1.0, 1.0); t.translate(-info.height, 0); t.translate(0, info.width); t.rotate(3 * Math.PI / 2); break; case 8: // PI / 2 t.translate(0, info.width); t.rotate(3 * Math.PI / 2); break; default: break; } return t; }
From source file:edu.umn.cs.spatialHadoop.operations.HeatMapPlot.java
private static <S extends Shape> void plotHeatMapLocal(Path inFile, Path outFile, OperationsParams params) throws IOException { int imageWidth = params.getInt("width", 1000); int imageHeight = params.getInt("height", 1000); Shape shape = params.getShape("shape", new Point()); Shape plotRange = params.getShape("rect", null); boolean keepAspectRatio = params.is("keep-ratio", true); InputSplit[] splits;/* w w w .j av a 2s . c o m*/ FileSystem inFs = inFile.getFileSystem(params); FileStatus inFStatus = inFs.getFileStatus(inFile); if (inFStatus != null && !inFStatus.isDir()) { // One file, retrieve it immediately. // This is useful if the input is a hidden file which is automatically // skipped by FileInputFormat. We need to plot a hidden file for the case // of plotting partition boundaries of a spatial index splits = new InputSplit[] { new FileSplit(inFile, 0, inFStatus.getLen(), new String[0]) }; } else { JobConf job = new JobConf(params); ShapeInputFormat<Shape> inputFormat = new ShapeInputFormat<Shape>(); ShapeInputFormat.addInputPath(job, inFile); splits = inputFormat.getSplits(job, 1); } boolean vflip = params.is("vflip"); Rectangle fileMBR; if (plotRange != null) { fileMBR = plotRange.getMBR(); } else { fileMBR = FileMBR.fileMBR(inFile, params); } if (keepAspectRatio) { // Adjust width and height to maintain aspect ratio if (fileMBR.getWidth() / fileMBR.getHeight() > (double) imageWidth / imageHeight) { // Fix width and change height imageHeight = (int) (fileMBR.getHeight() * imageWidth / fileMBR.getWidth()); } else { imageWidth = (int) (fileMBR.getWidth() * imageHeight / fileMBR.getHeight()); } } // Create the frequency map int radius = params.getInt("radius", 5); FrequencyMap frequencyMap = new FrequencyMap(imageWidth, imageHeight); for (InputSplit split : splits) { ShapeRecordReader<Shape> reader = new ShapeRecordReader<Shape>(params, (FileSplit) split); Rectangle cell = reader.createKey(); while (reader.next(cell, shape)) { Rectangle shapeBuffer = shape.getMBR(); if (shapeBuffer == null) continue; shapeBuffer = shapeBuffer.buffer(radius, radius); if (plotRange == null || shapeBuffer.isIntersected(plotRange)) { Point centerPoint = shapeBuffer.getCenterPoint(); int cx = (int) Math.round((centerPoint.x - fileMBR.x1) * imageWidth / fileMBR.getWidth()); int cy = (int) Math.round((centerPoint.y - fileMBR.y1) * imageHeight / fileMBR.getHeight()); frequencyMap.addPoint(cx, cy, radius); } } reader.close(); } // Convert frequency map to an image with colors NASAPoint.setColor1(params.getColor("color1", Color.BLUE)); NASAPoint.setColor2(params.getColor("color2", Color.RED)); NASAPoint.gradientType = params.getGradientType("gradient", NASAPoint.GradientType.GT_HUE); String valueRangeStr = params.get("valuerange"); MinMax valueRange = null; if (valueRangeStr != null) { String[] parts = valueRangeStr.contains("..") ? valueRangeStr.split("\\.\\.", 2) : valueRangeStr.split(",", 2); valueRange = new MinMax(Integer.parseInt(parts[0]), Integer.parseInt(parts[1])); } boolean skipZeros = params.getBoolean("skipzeros", false); BufferedImage image = frequencyMap.toImage(valueRange, skipZeros); if (vflip) { AffineTransform tx = AffineTransform.getScaleInstance(1, -1); tx.translate(0, -image.getHeight()); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); image = op.filter(image, null); } FileSystem outFs = outFile.getFileSystem(params); OutputStream out = outFs.create(outFile, true); ImageIO.write(image, "png", out); out.close(); }
From source file:Main.java
public void paint(Graphics g) { try {/*from ww w.jav a2 s.com*/ Graphics2D g2D; g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String fileName = "a.jpg"; Image img = getToolkit().getImage(fileName); AffineTransform aTran = new AffineTransform(); aTran.translate(50.0f, 20.0f); g2D.transform(aTran); g2D.drawImage(img, new AffineTransform(), this); } catch (Exception e) { } }
From source file:Shear.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; AffineTransform tx1 = new AffineTransform(); tx1.translate(50, 90); g2d.setTransform(tx1);// www . j ava 2 s . c o m g2d.setColor(Color.green); g2d.drawRect(0, 0, 80, 50); AffineTransform tx2 = new AffineTransform(); tx2.translate(50, 90); tx2.shear(0, 1); g2d.setTransform(tx2); g2d.setColor(Color.blue); g2d.draw(new Rectangle(0, 0, 80, 50)); }
From source file:Scale.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(150, 150, 150)); g2d.fillRect(0, 0, 80, 50);//from w w w. ja va 2 s. c o m AffineTransform tx1 = new AffineTransform(); tx1.translate(110, 20); tx1.scale(0.5, 0.5); g2d.setTransform(tx1); g2d.fillRect(0, 0, 80, 50); AffineTransform tx2 = new AffineTransform(); tx2.translate(200, 20); tx2.scale(1.5, 1.5); g2d.setTransform(tx2); g2d.fillRect(0, 0, 80, 50); }