Java: Saving Graphics to background BufferedImage [duplicate]

This question already has an answer here:

So right now my paint() repeatedly paints a BufferImage over and over again. Is there any way of adding new Graphics to this BufferedImage variable?

img is a variable that stores a .png file that we will draw over.

img = ImageIO.read(new File(fileName));

My paint() functions draws this .png image over and over again.

public void paint(Graphics g){
    g.drawImage(img, 0, 0, null);

    g.setColor(Color.RED);
    g.drawLine(startX, startY, endX, endY);
}

How would I add Graphics changes (i.e. lines) to the img variable?