java轴_JAVA2D:翻译轴
測試
public void BottomLeftOriginTest()引發(fā)IOException{
int寬度=256;
內(nèi)部高度=512;
bufferedimage bi=新bufferedimage(寬度、高度、bufferedimage.type_int_bgr);
graphics2d ig=bi.creategraphics();
//保存“舊”轉(zhuǎn)換
affinetransform old=ig.getTransform();
//原點在左上方:
//使用反轉(zhuǎn)的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(顏色.藍(lán)色);
ig.fillRect(0,0,bi.getWidth(),bi.getHeight());
ig.setcolor(顏色,紅色);
ig.圓角多邊形(xpoints、ypoints、npoints);
//還原舊轉(zhuǎn)換
ig.settransform(舊版);
//將結(jié)果導(dǎo)出到文件
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"));
}
總結(jié)
以上是生活随笔為你收集整理的java轴_JAVA2D:翻译轴的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java编码ppt_[2018年最新整理
- 下一篇: in the java search_L