How can I edit a jpg image through Java?

后端 未结 5 1492
名媛妹妹
名媛妹妹 2021-02-07 10:52

I have loaded a jpg image in which I want to draw letters and circles, given a x,y coordinate.

I have been trying to figure out the paintIcon of the ImageIcon class

<
5条回答
  •  萌比男神i
    2021-02-07 11:17

    I imagen you could use this method to overlay the elements you need every time the image is drawn in the UI (this would happen numerous times as you are not drawing ON the image data its self) but may be suitable to your purposes (and advantageous if the overlay changes over time).

    Something like:

    new ImageIcon("someUrl.png"){
        public void paintIcon(Component c, Graphics g, int x, int y) {
            super(c, g, x, y);
            g.translate(x, y);
    
            g.drawOval(0, 0, 10, 10);
            ...
    
            g.translate(-x, -y);
        }
    };
    

    Having said that, mmyers' answer is much better if you want to modify the image data.

提交回复
热议问题