Example #1
0
 public static bool SaveBitmapToFile(Bitmap bitmap, string filename, EnumImageFormat format, bool cropImage)
 {
     if (bitmap != null && !string.IsNullOrEmpty(filename))
     {
         if (cropImage)
         {
             DlgCropImage dlg = new DlgCropImage();
             dlg.LoadData(bitmap);
             dlg.ShowDialog();
             bitmap = dlg.Result as Bitmap;
         }
         if (bitmap != null)
         {
             if (System.IO.File.Exists(filename))
             {
                 System.IO.File.Delete(filename);
             }
             try
             {
                 using (Bitmap bm = new Bitmap(bitmap))
                 {
                     bm.Save(filename, VPLUtil.GetImageFormat(format));
                 }
                 return(true);
             }
             catch (Exception err)
             {
                 MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "Error saving image to [{0}]. Verify it is a valid file name. {1}", filename, err.Message));
             }
         }
     }
     return(false);
 }