List of usage examples for java.awt.geom AffineTransform getTranslateInstance
public static AffineTransform getTranslateInstance(double tx, double ty)
From source file:lucee.runtime.img.Image.java
public void grayscale() throws ExpressionException { BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_BYTE_GRAY); Graphics2D graphics = img.createGraphics(); graphics.drawImage(image(), new AffineTransformOp(AffineTransform.getTranslateInstance(0.0, 0.0), 1), 0, 0); graphics.dispose();/* w w w. j av a 2 s. c o m*/ image(img); }
From source file:lucee.runtime.img.Image.java
public void rgb() throws ExpressionException { BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_BYTE_INDEXED); Graphics2D graphics = img.createGraphics(); graphics.drawImage(image(), new AffineTransformOp(AffineTransform.getTranslateInstance(0.0, 0.0), 1), 0, 0); graphics.dispose();/*from www. j a v a 2 s.com*/ image(img); }
From source file:lucee.runtime.img.Image.java
public void threeBBger() throws ExpressionException { BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = img.createGraphics(); graphics.drawImage(image(), new AffineTransformOp(AffineTransform.getTranslateInstance(0.0, 0.0), 1), 0, 0); graphics.dispose();/*from w w w . j av a 2 s .c o m*/ image(img); }
From source file:lucee.runtime.img.Image.java
public void paste(Image topImage, int x, int y) throws ExpressionException { RenderingHints interp = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); BorderExtender extender = BorderExtender.createInstance(1); Graphics2D g = getGraphics(); g.addRenderingHints(new RenderingHints(JAI.KEY_BORDER_EXTENDER, extender)); g.drawImage(topImage.image(), (new AffineTransformOp(AffineTransform.getTranslateInstance(x, y), interp)), 0, 0);/*from ww w. jav a 2 s . c om*/ }
From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java
private BufferedImage rotateImage(BufferedImage masterImage, int angle) { int virtualAngle = getVirtualAngle(angle); Dimension size = new Dimension(masterImage.getWidth(), masterImage.getHeight()); int masterWidth = masterImage.getWidth(); int masterHeight = masterImage.getHeight(); double x = 0; //masterWidth / 2.0; double y = 0; //masterHeight / 2.0; switch (virtualAngle) { case 0:// ww w.j a v a 2 s .c o m break; case 180: break; case 90: case 270: size = new Dimension(masterImage.getHeight(), masterImage.getWidth()); x = (masterHeight - masterWidth) / 2.0; y = (masterWidth - masterHeight) / 2.0; break; } BufferedImage renderedImage = new BufferedImage(size.width, size.height, masterImage.getTransparency()); Graphics2D g2d = renderedImage.createGraphics(); AffineTransform at = AffineTransform.getTranslateInstance(x, y); at.rotate(Math.toRadians(virtualAngle), masterWidth / 2.0, masterHeight / 2.0); g2d.drawImage(masterImage, at, null); g2d.dispose(); return renderedImage; }
From source file:acmi.l2.clientmod.l2smr.Controller.java
@FXML private void exportSM() { List<Actor> actors = this.table.getSelectionModel().getSelectedItems().stream().map(Actor::clone) .collect(Collectors.toList()); if (actors.isEmpty()) return;/* w ww . j av a 2s. co m*/ int xy = 18 | (20 << 8); try { xy = getXY(getMapsDir(), this.unrChooser.getSelectionModel().getSelectedItem()); } catch (IOException e) { showAlert(Alert.AlertType.WARNING, "Export", null, "Couldn't read map coords, using default 18_20"); } ImportExportDialog dlg = new ImportExportDialog(xy & 0xff, (xy >> 8) & 0xff); ButtonType response = dlg.showAndWait().orElse(null); if (response != ButtonType.OK) return; FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON", "*.json")); fileChooser.setTitle("Save"); File file = fileChooser.showSaveDialog(getStage()); if (file == null) return; longTask(progress -> { float x = dlg.getX(), y = dlg.getY(), z = dlg.getZ(); double angle = dlg.getAngle(); AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI * angle / 180, x, y); AffineTransform translate = AffineTransform.getTranslateInstance(-x, -y); for (int i = 0; i < actors.size(); i++) { progress.accept((double) i / actors.size()); Actor o = actors.get(i); Point2D.Float point = new Point2D.Float(o.getX(), o.getY()); rotate.transform(point, point); translate.transform(point, point); o.setX(point.x); o.setY(point.y); o.setZ(o.getZ() - z); if (o.getYaw() == null) o.setYaw(0); o.setYaw(((int) (o.getYaw() + angle * 0xFFFF / 360)) & 0xFFFF); } progress.accept(-1.0); L2Map map = new L2Map(x, y, z, actors); ObjectMapper objectMapper = new ObjectMapper(); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { objectMapper.writeValue(baos, map); try (OutputStream fos = new FileOutputStream(file)) { baos.writeTo(fos); } } }, e -> onException("Export failed", e)); }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * This is used for the arrow of a directed and for one of the * arrows for non-directed edges/*w ww. j a v a 2 s.c om*/ * Get a transform to place the arrow shape on the passed edge at the * point where it intersects the passed shape * @param edgeShape * @param vertexShape * @return */ public AffineTransform getArrowTransform(Line2D edgeShape, Shape vertexShape) { float dx = (float) (edgeShape.getX1() - edgeShape.getX2()); float dy = (float) (edgeShape.getY1() - edgeShape.getY2()); // iterate over the line until the edge shape will place the // arrowhead closer than 'arrowGap' to the vertex shape boundary while ((dx * dx + dy * dy) > arrow_placement_tolerance) { try { edgeShape = getLastOutsideSegment(edgeShape, vertexShape); } catch (IllegalArgumentException e) { System.err.println(e.toString()); return null; } dx = (float) (edgeShape.getX1() - edgeShape.getX2()); dy = (float) (edgeShape.getY1() - edgeShape.getY2()); } double atheta = Math.atan2(dx, dy) + Math.PI / 2; AffineTransform at = AffineTransform.getTranslateInstance(edgeShape.getX1(), edgeShape.getY1()); at.rotate(-atheta); return at; }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * This is used for the reverse-arrow of a non-directed edge * get a transform to place the arrow shape on the passed edge at the * point where it intersects the passed shape * @param edgeShape// www. j a v a2 s .c om * @param vertexShape * @return */ protected AffineTransform getReverseArrowTransform(Line2D edgeShape, Shape vertexShape) { float dx = (float) (edgeShape.getX1() - edgeShape.getX2()); float dy = (float) (edgeShape.getY1() - edgeShape.getY2()); // iterate over the line until the edge shape will place the // arrowhead closer than 'arrowGap' to the vertex shape boundary while ((dx * dx + dy * dy) > arrow_placement_tolerance) { try { edgeShape = getFirstOutsideSegment(edgeShape, vertexShape); } catch (IllegalArgumentException e) { System.err.println(e.toString()); return null; } dx = (float) (edgeShape.getX1() - edgeShape.getX2()); dy = (float) (edgeShape.getY1() - edgeShape.getY2()); } // calculate the angle for the arrowhead double atheta = Math.atan2(dx, dy) - Math.PI / 2; AffineTransform at = AffineTransform.getTranslateInstance(edgeShape.getX1(), edgeShape.getY1()); at.rotate(-atheta); return at; }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * Paints the vertex <code>v</code> at the location <code>(x,y)</code> * on the graphics context <code>g_gen</code>. The vertex is painted * using the shape returned by this instance's <code>VertexShapeFunction</code>, * and the foreground and background (border) colors provided by this * instance's <code>VertexColorFunction</code>. Delegates drawing the * label (if any) for this vertex to <code>labelVertex</code>. *//* w w w.j a v a 2 s. com*/ public void paintVertex(Graphics g, Vertex v, int x, int y) { if (!vertexIncludePredicate.evaluate(v)) return; boolean vertexHit = true; Rectangle deviceRectangle = null; Graphics2D g2d = (Graphics2D) g; if (screenDevice != null) { Dimension d = screenDevice.getSize(); if (d.width <= 0 || d.height <= 0) { d = screenDevice.getPreferredSize(); } deviceRectangle = new Rectangle(0, 0, d.width, d.height); } Stroke old_stroke = g2d.getStroke(); Stroke new_stroke = vertexStrokeFunction.getStroke(v); if (new_stroke != null) { g2d.setStroke(new_stroke); } // get the shape to be rendered Shape s = vertexShapeFunction.getShape(v); // create a transform that translates to the location of // the vertex to be rendered AffineTransform xform = AffineTransform.getTranslateInstance(x, y); // transform the vertex shape with xtransform s = xform.createTransformedShape(s); vertexHit = viewTransformer.transform(s).intersects(deviceRectangle); if (vertexHit) { if (vertexIconFunction != null) { paintIconForVertex(g2d, v, x, y); } else { paintShapeForVertex(g2d, v, s); } if (new_stroke != null) { g2d.setStroke(old_stroke); } String label = vertexStringer.getLabel(v); if (label != null) { labelVertex(g, v, label, x, y); } } }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * Paint <code>v</code>'s icon on <code>g</code> at <code>(x,y)</code>. */// w w w. j a v a 2 s . com public void paintIconForVertex(Graphics g, Vertex v, int x, int y) { Icon icon = vertexIconFunction.getIcon(v); if (icon == null) { Shape s = AffineTransform.getTranslateInstance(x, y) .createTransformedShape(getVertexShapeFunction().getShape(v)); paintShapeForVertex((Graphics2D) g, v, s); } else { int xLoc = x - icon.getIconWidth() / 2; int yLoc = y - icon.getIconHeight() / 2; icon.paintIcon(screenDevice, g, xLoc, yLoc); } }