我必须在图形上绘制彩色地图.问题是我的图的原点可以在右侧或左侧.
是否可以从右向左绘制?
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);