java.awt.geom.AffineTransform.setToScale()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中java.awt.geom.AffineTransform.setToScale()方法的一些代码示例,展示了AffineTransform.setToScale()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AffineTransform.setToScale()方法的具体详情如下:
包路径:java.awt.geom.AffineTransform
类名称:AffineTransform
方法名:setToScale

AffineTransform.setToScale介绍

暂无

代码示例

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. public ShapeStroke(Shape shape, float width, float advance, float phase) {
  2. this.advance = advance;
  3. this.phase = phase;
  4. Rectangle2D bounds = shape.getBounds2D();
  5. double scale = width / bounds.getHeight();
  6. t.setToScale(scale, scale);
  7. t.translate(-bounds.getCenterX(), -bounds.getCenterY());
  8. this.theShape = t.createTransformedShape(shape);
  9. }

代码示例来源:origin: geotools/geotools

  1. /** Checks for {@linkplain #checkPermission permission} before setting this transform. */
  2. @Override
  3. public void setToScale(double sx, double sy) {
  4. checkPermission();
  5. super.setToScale(sx, sy);
  6. }

代码示例来源:origin: JChemPaint/jchempaint

  1. public void setTransform(AffineTransform transform) {
  2. this.transform = transform;
  3. this.transform.setToScale(30, -30);
  4. // System.err.println(transform.toString());
  5. // System.err.println(String.format("scale=%f zoom=%f\n", transform.getScaleX(), transform.getScaleY()));
  6. }

代码示例来源:origin: stackoverflow.com

  1. double xScale = 100/image.getWidth();
  2. double yScale = 300/image.getHeight();
  3. AffineTransform transform = new AffineTransform();
  4. transform.setToScale( xScale, yScale );
  5. //paint code goes here

代码示例来源:origin: stackoverflow.com

  1. double xScale = 100/image.getWidth();
  2. double yScale = 300/image.getHeight();
  3. double theScale = xScale > yScale ? xScale : yScale;
  4. AffineTransform transform = new AffineTransform();
  5. transform.setToScale( theScale , theScale );
  6. //paint code goes here

代码示例来源:origin: uk.ac.ebi.caf/caf-utility

  1. private AffineTransform transform(int length) {
  2. transform = new AffineTransform();
  3. if (flip == Flip.Horizontal) {
  4. transform.setToScale(-1, 1);
  5. transform.translate(-length, 0);
  6. }
  7. return transform;
  8. }

代码示例来源:origin: stackoverflow.com

  1. public static void main(String[] args) throws IOException {
  2. BufferedImage image = ImageIO.read(new File("test.jpg"));
  3. BufferedImage mirrored = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
  4. Graphics2D graphics = (Graphics2D)mirrored.getGraphics();
  5. AffineTransform transform = new AffineTransform();
  6. transform.setToScale(1, -1);
  7. transform.translate(0, -image.getHeight());
  8. graphics.setTransform(transform);
  9. graphics.drawImage(image, 0, 0, null);
  10. ImageIO.write(mirrored, "jpg", new File("test-flipped.jpg"));
  11. }

代码示例来源:origin: apache/sis

  1. /**
  2. * Checks for {@linkplain #checkPermission() permission} before setting this transform.
  3. */
  4. @Override
  5. public final void setToScale(double sx, double sy) {
  6. checkPermission();
  7. super.setToScale(sx, sy);
  8. }

代码示例来源:origin: org.apache.sis.core/sis-referencing

  1. /**
  2. * Checks for {@linkplain #checkPermission() permission} before setting this transform.
  3. */
  4. @Override
  5. public final void setToScale(double sx, double sy) {
  6. checkPermission();
  7. super.setToScale(sx, sy);
  8. }

代码示例来源:origin: ThomasFooteDQ/DroidQuest

  1. public void componentResized(ComponentEvent e) {
  2. Dimension d = new Dimension();
  3. getSize(d);
  4. double w = d.width / 560.0;
  5. double h = d.height / 384.0;
  6. at.setToScale(w, h);
  7. }
  8. });

代码示例来源:origin: cytoscape/application

  1. private void adjustShape() {
  2. final double shapeWidth = shape.getBounds2D().getWidth();
  3. final double shapeHeight = shape.getBounds2D().getHeight();
  4. final double xRatio = width / shapeWidth;
  5. final double yRatio = height / shapeHeight;
  6. final AffineTransform af = new AffineTransform();
  7. final Rectangle2D bound = shape.getBounds2D();
  8. final double minx = bound.getMinX();
  9. final double miny = bound.getMinY();
  10. if (minx < 0) {
  11. af.setToTranslation(Math.abs(minx), 0);
  12. shape = af.createTransformedShape(shape);
  13. }
  14. if (miny < 0) {
  15. af.setToTranslation(0, Math.abs(miny));
  16. shape = af.createTransformedShape(shape);
  17. }
  18. af.setToScale(xRatio, yRatio);
  19. shape = af.createTransformedShape(shape);
  20. }

代码示例来源:origin: org.boofcv/visualize

  1. @Override
  2. public void paintComponent(Graphics g) {
  3. if( img != null) {
  4. Graphics2D g2 = (Graphics2D)g;
  5. g2.setColor(Color.WHITE);
  6. g2.fillRect(0,0,getWidth(),getHeight());
  7. double scale = img.getWidth()/(double)getWidth();
  8. if( scale > 1 ) {
  9. AffineTransform tran = new AffineTransform();
  10. tran.setToScale(1.0/scale,1.0/scale);
  11. g2.drawImage(img,tran,null);
  12. } else {
  13. g.drawImage(img, 0, 0, this);
  14. }
  15. }
  16. }
  17. }

代码示例来源:origin: org.boofcv/boofcv-swing

  1. @Override
  2. public void paintComponent(Graphics g) {
  3. if( img != null) {
  4. Graphics2D g2 = (Graphics2D)g;
  5. g2.setColor(Color.WHITE);
  6. g2.fillRect(0,0,getWidth(),getHeight());
  7. double scale = img.getWidth()/(double)getWidth();
  8. if( scale > 1 ) {
  9. AffineTransform tran = new AffineTransform();
  10. tran.setToScale(1.0/scale,1.0/scale);
  11. g2.drawImage(img,tran,null);
  12. } else {
  13. g.drawImage(img, 0, 0, this);
  14. }
  15. }
  16. }
  17. }

代码示例来源:origin: dk.apaq.printing/printing-facade-core

  1. public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
  2. if(pageIndex!=0) {
  3. return NO_SUCH_PAGE;
  4. }
  5. Graphics2D g2d = (Graphics2D) graphics;
  6. AffineTransform at = new AffineTransform();
  7. at.translate(0, 0);
  8. //We need to scale the image properly so that it fits on one page.
  9. double xScale = pageFormat.getWidth() / image.getWidth();
  10. double yScale = pageFormat.getHeight() / image.getHeight();
  11. // Maintain the aspect ratio by taking the min of those 2 factors and using it to scale both dimensions.
  12. double aspectScale = Math.min(xScale, yScale);
  13. at.setToScale(aspectScale, aspectScale);
  14. g2d.drawRenderedImage(image, at);
  15. return Printable.PAGE_EXISTS;
  16. }

代码示例来源:origin: mikaelhg/openblocks

  1. /**
  2. * update zoom for this button
  3. * @param newZoom
  4. */
  5. public void setZoomLevel(double newZoom) {
  6. Font renderingFont;
  7. AffineTransform at = new AffineTransform();
  8. at.setToScale(newZoom, newZoom);
  9. renderingFont = this.getFont().deriveFont(at);
  10. this.setFont(renderingFont);
  11. this.repaint();
  12. }

代码示例来源:origin: stackoverflow.com

  1. File f = new File("awesome_tiger.svg");
  2. g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  3. SVGUniverse svgUniverse = new SVGUniverse();
  4. try {
  5. SVGDiagram diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(f.toURI().toURL()));
  6. try {
  7. AffineTransform at = new AffineTransform();
  8. at.setToScale(jdpPane.getWidth()/diagram.getWidth(), jdpPane.getWidth()/diagram.getWidth());
  9. g.transform(at);
  10. diagram.render(g);
  11. }
  12. catch(Exception e2) {System.out.println(e2);}}
  13. catch (Exception ex) {System.out.println(ex);}

代码示例来源:origin: mikaelhg/openblocks

  1. public void setZoomLevel(double newZoom) {
  2. this.zoom = newZoom;
  3. Font renderingFont;// = new Font(font.getFontName(), font.getStyle(), (int)(font.getSize()*newZoom));
  4. AffineTransform at = new AffineTransform();
  5. at.setToScale(newZoom, newZoom);
  6. renderingFont = this.getFont().deriveFont(at);
  7. this.setFont(renderingFont);
  8. this.repaint();
  9. this.updateDimensions();
  10. }

代码示例来源:origin: geotools/geotools

  1. tr.setToScale(1, f);
  2. assertEquals(1, XAffineTransform.getScaleX0(tr), EPS);
  3. assertEquals(1, XAffineTransform.getScaleY0(tr), EPS);
  4. tr.setToScale(2, 3 * f);
  5. assertEquals(2, XAffineTransform.getScaleX0(tr), EPS);
  6. assertEquals(3, XAffineTransform.getScaleY0(tr), EPS);

代码示例来源:origin: openstreetmap/osmembrane

  1. @Override
  2. public void resetView() {
  3. double zoomFactor = PipelinePanel.DEFAULT_ZOOM
  4. * (Double) ModelProxy.getInstance().getSettings()
  5. .getValue(SettingType.DEFAULT_ZOOM_SIZE);
  6. objectToWindow.setToScale(zoomFactor, zoomFactor);
  7. arrange(true);
  8. }

代码示例来源:origin: hneemann/Digital

  1. /**
  2. * maximizes the circuit shown
  3. */
  4. public void fitCircuit() {
  5. GraphicMinMax gr = new GraphicMinMax();
  6. circuit.drawTo(gr);
  7. AffineTransform newTrans = new AffineTransform();
  8. if (gr.getMin() != null && getWidth() != 0 && getHeight() != 0) {
  9. Vector delta = gr.getMax().sub(gr.getMin());
  10. double sx = ((double) getWidth()) / (delta.x + Style.NORMAL.getThickness() * 2);
  11. double sy = ((double) getHeight()) / (delta.y + Style.NORMAL.getThickness() * 2);
  12. double s = Math.min(sx, sy);
  13. newTrans.setToScale(s, s); // set Scaling
  14. Vector center = gr.getMin().add(gr.getMax()).div(2);
  15. newTrans.translate(-center.x, -center.y); // move drawing center to (0,0)
  16. Vector dif = new Vector(getWidth(), getHeight()).div(2);
  17. newTrans.translate(dif.x / s, dif.y / s); // move drawing center to frame center
  18. isManualScale = false;
  19. } else {
  20. isManualScale = true;
  21. }
  22. if (!newTrans.equals(transform)) {
  23. transform = newTrans;
  24. repaintNeeded();
  25. }
  26. }

相关文章