欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

java轴_JAVA2D:翻译轴

发布时间:2025/3/21 编程问答 23 豆豆
生活随笔 收集整理的这篇文章主要介绍了 java轴_JAVA2D:翻译轴 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

测试

public void BottomLeftOriginTest()引发IOException{

int宽度=256;

内部高度=512;

bufferedimage bi=新bufferedimage(宽度、高度、bufferedimage.type_int_bgr);

graphics2d ig=bi.creategraphics();

//保存“旧”转换

affinetransform old=ig.getTransform();

//原点在左上方:

//使用反转的Y变换更新图形对象

如果(真)/*订购正常*/

ig.比例(1.0,-1.0);

ig.translate(0,-bi.getheight());

}否则{

ig.translate(0,-bi.getheight());

ig.比例(1.0,-1.0);

}

int xpoints[]=新int[]0,宽度,宽度

int ypoints[]=新int[]0,高度,0

int npoints=xpoints.length;

ig.setcolor(颜色.蓝色);

ig.fillRect(0,0,bi.getWidth(),bi.getHeight());

ig.setcolor(颜色,红色);

ig.圆角多边形(xpoints、ypoints、npoints);

//还原旧转换

ig.settransform(旧版);

//将结果导出到文件

imageio.write(bi,“png”,新文件(“origin.png”));

}

< /代码>

LP未来的某人:

@Test

public void bottomLeftOriginTest() throws IOException {

int width = 256;

int height = 512;

BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);

Graphics2D ig = bi.createGraphics();

// save the "old" transform

AffineTransform old = ig.getTransform();

// origin is top left:

// update graphics object with the inverted y-transform

if (true) { /* order ok */

ig.scale(1.0, -1.0);

ig.translate(0, -bi.getHeight());

} else {

ig.translate(0, -bi.getHeight());

ig.scale(1.0, -1.0);

}

int xPoints[] = new int[] { 0, width, width };

int yPoints[] = new int[] { 0, height, 0 };

int nPoints = xPoints.length;

ig.setColor(Color.BLUE);

ig.fillRect(0, 0, bi.getWidth(), bi.getHeight());

ig.setColor(Color.RED);

ig.fillPolygon(xPoints, yPoints, nPoints);

// restore the old transform

ig.setTransform(old);

// Export the result to a file

ImageIO.write(bi, "PNG", new File("origin.png"));

}

总结

以上是生活随笔为你收集整理的java轴_JAVA2D:翻译轴的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。