SoFunction
Updated on 2025-03-07

C# Manual/automatically save the example code of the picture

//Save pictures manually
        private void saveBtn_Click(object sender, e)  
        {  
            bool isSave = true;  
            SaveFileDialog saveImageDialog = new SaveFileDialog();  
= "Picture Save";
            = @"jpeg|*.jpg|bmp|*.bmp|gif|*.gif";  

            if(() == )  
            {  
                string fileName = ();  

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

                    imgformat = null;       

                    if(fileExtName!="")  
                    {  
                        switch(fileExtName)   
                        {   
                            case "jpg":   
                                imgformat = ;   
                                break;   
                            case "bmp":   
                                imgformat = ;   
                                break;   
                            case "gif":   
                                imgformat = ;   
                                break;   
                            default:   
("Only access to: jpg,bmp,gif format");
                                isSave = false;  
                                break;   
                        }   

                    }  

//Save in JPG format by default
                    if(imgformat == null)  
                    {  
                        imgformat = ;  
                    }  

                    if(isSave)  
                    {  
                        try 
                        {  
                                this.(fileName,imgformat);  
//("The picture has been saved successfully!");
                        }  
                        catch 
                        {  
("Save failed, you have not caught the picture or have cleared the picture!");
                        }  
                    }  

                }  

            }  
        }  

//Automatically save pictures
        private void Autosave()  
        {  
            string Opath =@"D:\VedioCapture\Photo";  
            string photoname = ();  
            if ((-1, 1) != @"\")  
                Opath = Opath + @"\";  
            string path1 = Opath + ();  
            if (! (path1))            
                (path1);  
            //(path1 +"\\" + photoname + ".jpg",);  
//Image reduction
            objPic,objNewPic;  
            try 
            {  
                objPic = new ();  
                objNewPic=new (objPic,,);  
//objNewPic=new (objPic,320,240);//The size and size of the image saved
                (path1 +"\\" + photoname + ".jpg",);  
            }  
            catch(Exception exp){throw exp;}  
            finally 
            {  
                objPic=null;  
                objNewPic=null;  
            }  
        }