示例#1
0
 private Bitmap GetStudentPhoto(string photoPath)
 {
     try
     {
         Bitmap res;
         if (File.Exists(photoPath))
         {
             res = (Bitmap)Image.FromFile(photoPath);
         }
         else if ((File.Exists(photoPath + ".jpg")))
         {
             res = (Bitmap)Image.FromFile(photoPath + ".jpg");
         }
         else if ((File.Exists(photoPath + ".png")))
         {
             res = (Bitmap)Image.FromFile(photoPath + ".png");
         }
         else if ((File.Exists(photoPath + ".jpg.jpg")))
         {
             res = (Bitmap)Image.FromFile(photoPath + ".jpg.jpg");
         }
         else
         {
             return(null);
         }
         //if (res.Height / res.Width > 271.0 / 196.0)
         res = ImageEx.SmallPicH(res, 271);
         if (res.Width < 196)
         {
             res = ImageEx.SmallPic(res, 196);
         }
         //else
         //    res = ImageEx.SmallPic(res, 196);
         res = ImageEx.CutImage(res, new Rectangle((res.Width - 196) / 2, 0, 196, 271));
         return(res);
     }
     catch
     {
         return(null);
     }
 }