开发者

Drawing an image from right to left

I have to draw a colored map on a graph. The problem is that my graph can have its origin at the开发者_运维问答 right or the left. Is it possible to draw from right to left ?

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);


Yes, use an AffineTransform and invert the x axis:

AffineTransform at = new AffineTransform();
at.scale(-1, 1);
at.translate((int)origin_x + 1, (int)origin_y + 1);

g2d.drawImage(image, at, null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜