为什么这个代码保存出来的图片是一片空白

不给你听 发布于 2015/06/22 09:37
阅读 170
收藏 0
package adventuregame;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class TestGame 
{
public void test() throws IOException
{
Image Img=Toolkit.getDefaultToolkit().createImage("e:/Map1.JPG");
BufferedImage img=new BufferedImage(10000,800,BufferedImage.TYPE_INT_RGB);
Graphics g=img.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0,10000,800);
g.drawImage(Img, 0, 0,null);
g.dispose();
ImageIO.write(img,"JPG",new File("e:/Map0.JPG"));
}
public static void main(String []args) throws IOException
{
TestGame tg=new TestGame();
tg.test();
}
}

加载中
0
天命剑主
天命剑主

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Main
{
    public void test() throws IOException
    {
        Image Img=ImageIO.read(new File("e:/Map1.JPG"));
        BufferedImage img=new BufferedImage(10000,800,BufferedImage.TYPE_INT_RGB);
        Graphics g=img.getGraphics();
        g.setColor(Color.white);
        g.fillRect(0, 0,10000,800);
        g.drawImage(Img, 0, 0,null);
        g.dispose();
        ImageIO.write(img,"JPG",new File("e:/Map0.JPG"));
    }
    public static void main(String []args) throws IOException
    {
        Main tg=new Main();
        tg.test();
    }
}



0
loyal
loyal

...你本来就画了一个空白...

底色白色...

填充矩形...白色...

不是白色就见鬼了...

返回顶部
顶部