国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 昌图县| 镇沅| 宁乡县| 渝北区| 墨脱县| 广灵县| 科技| 揭阳市| 名山县| 健康| 闸北区| 高州市| 金阳县| 丘北县| 山东| 汽车| 高雄市| 泾源县| 巫山县| 蒙阴县| 乃东县| 天长市| 香格里拉县| 林周县| 古浪县| 邯郸县| 三门县| 仙桃市| 获嘉县| 阳山县| 南京市| 台湾省| 台前县| 牙克石市| 屯昌县| 历史| 辉南县| 蒲城县| 师宗县| 英超| 英超|