当前位置:编程学习 > JAVA >>

一个图片的输入输出程序,第一次调用某方法会中断,第二次调用则正常

本人新手刚学JAVA几天。
这个程序要做的就是打开一张图片,先把他压缩成等宽高指定大小的图片,然后把它切割成9张方格图片并保存在电脑中。以下为主要的相关代码
else if(button.equals("set")){//修改所选图片
try {
setChange();
} catch (IOException e) {
e.printStackTrace();
}
         }


public void setChange() throws IOException{
Cutimage c=new Cutimage();
getDifficulty();
cou[K]++;
loaderimg();
InputStream in = new FileInputStream(spath);  
File directory = new File("");//设定为当前文件夹    
OutputStream out = new FileOutputStream(directory.getCanonicalPath()+"/pic_"+K+cou[K]+".jpg"); 
        c.Resize(in,out, MAX_SIZE,"jpg"); 
new MyMainFrame();
//c.Del(K);
dispose();
}


 public void Resize(InputStream is,OutputStream os,int size,String format) throws IOException{
     BufferedImage prevImage=ImageIO.read(is);
BufferedImage image = new BufferedImage(size, size, 
     BufferedImage.TYPE_INT_BGR); 
Graphics graphics = image.createGraphics(); 
graphics.drawImage(prevImage, 0, 0, size, size, null);
ImageIO.write(image,format,os); 
os.flush(); 
is.close(); 
os.close();
    }
以上相关的部分代码

Debug的时候setChange()第一次会出现
This Debug perspective is design to support application debugging.It incorporates views for displaying the debug stack,variables and breakpoint managent.
Do you want to open to open this perspective now?

正常情况下文件夹会生成9张图片,但是只生成了3张就停止了。
再次调用setChange的时候就可以正常运行了,生成了9张图片
好像跟IOException有关,谁能帮我分析下
补充:Java ,  Eclipse
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,