java-从右到左绘制图像
作者:互联网
我必须在图形上绘制彩色地图.问题是我的图的原点可以在右侧或左侧.
是否可以从右向左绘制?
double origin_x = xPositionToPixel(0.0);
double origin_y = yPositionToPixel(0.0);
BufferedImage image = new BufferedImage(values.length, values[0].length, BufferedImage.TYPE_INT_ARGB);
Graphics2D gImg = (Graphics2D)image.getGraphics();
for (int i = 0; i < values.length; i++) {
Double[] dValues = values[i];
for (int j = 0; j < dValues.length; j++) {
double value = dValues[j];
gImg.setColor(ColorMap.getPixelColor(value));
gImg.drawRect(i, j, 1, 1);
}
}
g2.drawImage(image, (int)origin_x + 1, (int)origin_y + 1, null);
解决方法:
是的,使用AffineTransform并反转x轴:
AffineTransform at = new AffineTransform();
at.scale(-1, 1);
at.translate((int)origin_x + 1, (int)origin_y + 1);
g2d.drawImage(image, at, null);
标签:graphics2d,swing,graph,java 来源: https://codeday.me/bug/20191102/1993876.html