Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 346
wotan2009 Avatar asked Dec 01 '25 16:12

wotan2009


1 Answers

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);
like image 165
dacwe Avatar answered Dec 04 '25 07:12

dacwe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!