Not sure if it is right or not, but i have a question with showing difference result by using difference way to do it.

My idea: put "Really original.png"(small image) image on the 2.png(large image).

The both code are working fine, but if i tried to comment out the method1's g.drawImage(image, 0, 0, null); It will only show the "Really Original.png" this part, and other part all black., but why method2 doesn't have this problem??

I also confuse g.drawImage(Image img,, x, y, Image img,); In here img will be the small image(Really original.png)??? and x, y are large image(2.png) where i want to put small image in there??

method1:

ImageIcon icon = new ImageIcon("C:/TEMP/2.png");
image = icon.getImage();
ImageIcon icon2 = new ImageIcon("C:/TEMP/Really Original.png");
image2 = icon2.getImage();

BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(),
        icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);

Graphics g = bufferedImage.getGraphics();
g.drawImage(image, 0, 0, null);
g.drawImage(image2, 0, icon.getIconHeight()-200, null);

method2:

try
{
    File origFile = new File("C:/TEMP/2.png");
    ImageIcon icon = new ImageIcon(origFile.getPath());
     source = ImageIO.read(origFile);
     logo = ImageIO.read(new File("C:/TEMP/Really Original.png"));

    Graphics g = source.getGraphics();
    g.drawImage(logo, 0, icon.getIconHeight()-200, null);
}
catch (Exception e)
{
    e.printStackTrace();
}
有帮助吗?

解决方案

The reason method 2 doesn't have the "problem" with not painting an image doesn't paint the image, is that the source image already contains the part you are not painting. If that makes any sense to you (sorry, but it is really hard to understand what you are asking).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top