- 爱易网页
- 
                            C#教程
- 修改一个图片的大小解决方案 
日期:2014-05-19  浏览次数:20962 次 
                    
                        
                         修改一个图片的大小
我想修改某一目录下的图片的大小. 
 我用如下方法: 
 private   void   button1_Click(object   sender,   EventArgs   e) 
                         { 
                                     OpenFileDialog   opd   =   new   OpenFileDialog(); 
                                     if   (opd.ShowDialog()   ==   DialogResult.OK) 
                                     { 
                                                 System.Drawing.Bitmap   objPic,   objNewPic; 
                                                 try 
                                                 { 
                                                             objPic   =   new   Bitmap(Image.FromFile(opd.FileName)); 
                                                             objNewPic   =   new   System.Drawing.Bitmap(objPic,   80,   80); 
                                                             objNewPic.Save(opd.FileName); 
  
                                                 } 
                                                 catch   (Exception   exp)   {   throw   exp;   } 
                                                 finally 
                                                 { 
                                                             objPic   =   null; 
                                                             objNewPic   =   null; 
                                                 } 
                                     } 
                         } 
 程序总是报错,可能是因为文件正在使用过程中,请问各位我该如何写?
------解决方案--------------------
 
  
  
 private void button1_Click(object sender, EventArgs e) 
         { 
             OpenFileDialog opd = new OpenFileDialog(); 
             if (opd.ShowDialog() == DialogResult.OK) 
             { 
                 System.Drawing.Bitmap objPic, objNewPic; 
                 try 
                 { 
                     objPic = new Bitmap(Image.FromFile(opd.FileName)); 
                     objNewPic = new System.Drawing.Bitmap(objPic, 80, 80); 
                     objNewPic.Save(opd.FileName+ ".tmp "); 
  
                 } 
                 catch (Exception exp) { throw exp; } 
                 finally