C# 图像截取

 public static Bitmap CropBitmap(Bitmap bitmap, int cropX, int cropY, int cropWidth, int cropHeight)        

{            

      Rectangle rect = new Rectangle(cropX, cropY, cropWidth, cropHeight);   

      Bitmap cropped = bitmap.Clone(rect, bitmap.PixelFormat);   

     return cropped;      

   }

        static void  Main(string[] args)       

  {         

      string path = "c:\\temped";         

      DirectoryInfo dic = new DirectoryInfo(path);          

      FileInfo[] files =  dic.GetFiles().OrderBy(item=>item.CreationTime).ToArray();      

       foreach (FileInfo item in files)          

     {           

           if (item.Extension == ".bmp")     

            {                   

                      string name = item.FullName;   

                      Image im = Image.FromFile(item.FullName);      

                       Bitmap bt = new Bitmap(im);                   

                      im.Dispose();                 

                         Bitmap newBit = CropBitmap(bt, 52, 62, 253, 249);   

                         File.Delete(item.FullName);                  

                         newBit.Save(name);                        

                  }

            }

}

posted @ 2013-01-21 19:21  louiskoo  阅读(683)  评论(0编辑  收藏  举报