打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
C#手动自动保存图片
  1. //手动保存图片  
  2.         private void saveBtn_Click(object sender, System.EventArgs e)  
  3.         {  
  4.             bool isSave = true;  
  5.             SaveFileDialog saveImageDialog = new SaveFileDialog();  
  6.             saveImageDialog.Title = "图片保存";  
  7.             saveImageDialog.Filter= @"jpeg|*.jpg|bmp|*.bmp|gif|*.gif";  
  8.   
  9.             if(saveImageDialog.ShowDialog() == DialogResult.OK)  
  10.             {  
  11.                 string fileName = saveImageDialog.FileName.ToString();  
  12.        
  13.                 if(fileName != "" && fileName != null)  
  14.                 {  
  15.                     string fileExtName = fileName.Substring(fileName.LastIndexOf(".")+1).ToString();  
  16.   
  17.                     System.Drawing.Imaging.ImageFormat imgformat = null;       
  18.    
  19.                     if(fileExtName!="")  
  20.                     {  
  21.                         switch(fileExtName)   
  22.                         {   
  23.                             case "jpg":   
  24.                                 imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;   
  25.                                 break;   
  26.                             case "bmp":   
  27.                                 imgformat = System.Drawing.Imaging.ImageFormat.Bmp;   
  28.                                 break;   
  29.                             case "gif":   
  30.                                 imgformat = System.Drawing.Imaging.ImageFormat.Gif;   
  31.                                 break;   
  32.                             default:   
  33.                                 MessageBox.Show("只能存取为: jpg,bmp,gif 格式");   
  34.                                 isSave = false;  
  35.                                 break;   
  36.                         }   
  37.   
  38.                     }  
  39.   
  40.                     //默认保存为JPG格式  
  41.                     if(imgformat == null)  
  42.                     {  
  43.                         imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;  
  44.                     }  
  45.                       
  46.                     if(isSave)  
  47.                     {  
  48.                         try  
  49.                         {  
  50.                                 this.pictureBox1.Image.Save(fileName,imgformat);  
  51.                                 //MessageBox.Show("图片已经成功保存!");  
  52.                         }  
  53.                         catch  
  54.                         {  
  55.                             MessageBox.Show("保存失败,你还没有截取过图片或已经清空图片!");  
  56.                         }  
  57.                     }  
  58.   
  59.                 }  
  60.   
  61.             }  
  62.         }  
  63.   
  64.         //自动保存图片  
  65.         private void Autosave()  
  66.         {  
  67.             string Opath =@"D:/VedioCapture/Photo";  
  68.             string photoname = DateTime.Now.Ticks.ToString();  
  69.             if (Opath.Substring(Opath.Length-1, 1) != @"/")  
  70.                 Opath = Opath + @"/";  
  71.             string path1 = Opath + DateTime.Now.ToShortDateString();  
  72.             if (! Directory.Exists(path1))            
  73.                 Directory.CreateDirectory(path1);  
  74.             //pictureBox1.Image.Save(path1 +"//" + photoname + ".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);  
  75.             //图像的缩小  
  76.             System.Drawing.Bitmap objPic,objNewPic;  
  77.             try  
  78.             {  
  79.                 objPic = new System.Drawing.Bitmap(pictureBox1.Image);  
  80.                 objNewPic=new System.Drawing.Bitmap(objPic,pictureBoxShow.Width,pictureBoxShow.Height);  
  81.                 //objNewPic=new System.Drawing.Bitmap(objPic,320,240);//图片保存的大小尺寸  
  82.                 objNewPic.Save(path1 +"//" + photoname + ".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);  
  83.             }  
  84.             catch(Exception exp){throw exp;}  
  85.             finally  
  86.             {  
  87.                 objPic=null;  
  88.                 objNewPic=null;  
  89.             }  
  90.         }  

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C# :实现水印与图片合成,并利用Graphics 压缩图像质量 , (委托实现listB...
用C#实现图片的缩放
C#截图操作方法大全
c#如何将图片转化为二进制,并将这个二进制码转化为图片
如何在没有 System.Drawing.Common 的情况下使用 C# 获取图片格式
Screen Capture and Save as an Image
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服