Hello!
How can i copy an image (gif) or a part of image into another image in java?
Hello!
How can i copy an image (gif) or a part of image into another image in java?
First load your image, i.e.
BufferedImage image = ImageIO.read(new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream("myimage.gif")));
To get a new subsection of that image, do something like this:
BufferedImage subImage = image.getSubImage(0,0,100,100);
The image above created above is the 100 pixel by 100 pixel square section from the top left corner of the original image. Then, to draw that sub image onto an already existing image, you could do this:
Graphics2D g = existingImage.createGraphics();
g.drawImage(subImage,0,0,null);
Now that 100 by 100 section of the original image is drawn onto a different, already existing image.