我必须在图表上绘制彩色地图。问题是我的图形可以在右边或左边。 是否可以从右到左画画?
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);
答案 0 :(得分:4)
是的,使用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);