国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C# 手動/自動保存圖片的實例代碼

2020-01-24 03:32:18
字體:
供稿:網(wǎng)友

view plaincopy to clipboardprint?

復制代碼 代碼如下:

//手動保存圖片  
        private void saveBtn_Click(object sender, System.EventArgs e)  
        {  
            bool isSave = true;  
            SaveFileDialog saveImageDialog = new SaveFileDialog();  
            saveImageDialog.Title = "圖片保存";  
            saveImageDialog.Filter= @"jpeg|*.jpg|bmp|*.bmp|gif|*.gif";  

            if(saveImageDialog.ShowDialog() == DialogResult.OK)  
            {  
                string fileName = saveImageDialog.FileName.ToString();  

                if(fileName != "" && fileName != null)  
                {  
                    string fileExtName = fileName.Substring(fileName.LastIndexOf(".")+1).ToString();  

                    System.Drawing.Imaging.ImageFormat imgformat = null;       

                    if(fileExtName!="")  
                    {  
                        switch(fileExtName)   
                        {   
                            case "jpg":   
                                imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;   
                                break;   
                            case "bmp":   
                                imgformat = System.Drawing.Imaging.ImageFormat.Bmp;   
                                break;   
                            case "gif":   
                                imgformat = System.Drawing.Imaging.ImageFormat.Gif;   
                                break;   
                            default:   
                                MessageBox.Show("只能存取為: jpg,bmp,gif 格式");   
                                isSave = false;  
                                break;   
                        }   

                    }  

                    //默認保存為JPG格式  
                    if(imgformat == null)  
                    {  
                        imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;  
                    }  

                    if(isSave)  
                    {  
                        try 
                        {  
                                this.pictureBox1.Image.Save(fileName,imgformat);  
                                //MessageBox.Show("圖片已經(jīng)成功保存!");  
                        }  
                        catch 
                        {  
                            MessageBox.Show("保存失敗,你還沒有截取過圖片或已經(jīng)清空圖片!");  
                        }  
                    }  

                }  

            }  
        }  

        //自動保存圖片  
        private void Autosave()  
        {  
            string Opath =@"D:/VedioCapture/Photo";  
            string photoname = DateTime.Now.Ticks.ToString();  
            if (Opath.Substring(Opath.Length-1, 1) != @"/")  
                Opath = Opath + @"/";  
            string path1 = Opath + DateTime.Now.ToShortDateString();  
            if (! Directory.Exists(path1))            
                Directory.CreateDirectory(path1);  
            //pictureBox1.Image.Save(path1 +"http://" + photoname + ".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);  
            //圖像的縮小  
            System.Drawing.Bitmap objPic,objNewPic;  
            try 
            {  
                objPic = new System.Drawing.Bitmap(pictureBox1.Image);  
                objNewPic=new System.Drawing.Bitmap(objPic,pictureBoxShow.Width,pictureBoxShow.Height);  
                //objNewPic=new System.Drawing.Bitmap(objPic,320,240);//圖片保存的大小尺寸  
                objNewPic.Save(path1 +"http://" + photoname + ".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);  
            }  
            catch(Exception exp){throw exp;}  
            finally 
            {  
                objPic=null;  
                objNewPic=null;  
            }  
        }

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 松江区| 于都县| 丰宁| 麻城市| 仁化县| 黎川县| 台南县| 金华市| 南平市| 新沂市| 修水县| 陈巴尔虎旗| 定南县| 湖南省| 德安县| 渝中区| 阜新市| 和静县| 湛江市| 赤峰市| 昭平县| 丰镇市| 嘉善县| 武胜县| 富民县| 耒阳市| 西华县| 湄潭县| 平遥县| 怀来县| 漳平市| 信阳市| 孟津县| 大安市| 手游| 万山特区| 扶绥县| 张掖市| 尼勒克县| 绥棱县| 克什克腾旗|