C# 手動(dòng)/自動(dòng)保存圖片的實(shí)例代碼
view plaincopy to clipboardprint?
//手動(dòng)保存圖片
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;
}
}
//默認(rèn)保存為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)清空?qǐng)D片!");
}
}
}
}
}
//自動(dò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 +"\\" + 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 +"\\" + photoname + ".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch(Exception exp){throw exp;}
finally
{
objPic=null;
objNewPic=null;
}
}
相關(guān)文章
C#實(shí)現(xiàn)文本轉(zhuǎn)語(yǔ)音功能
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)文本轉(zhuǎn)語(yǔ)音功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03C#使用系統(tǒng)方法發(fā)送異步郵件完整實(shí)例
這篇文章主要介紹了C#使用系統(tǒng)方法發(fā)送異步郵件實(shí)現(xiàn)方法,結(jié)合完整實(shí)例形式分析了C#異步調(diào)用與郵件發(fā)送的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07win7中C#的winForm編程使用savefiledialog不能彈出保存窗體的解決方法
這篇文章主要介紹了win7中C#的winForm編程使用savefiledialog不能彈出保存窗體的解決方法,涉及針對(duì)線程的調(diào)用問題,是比較實(shí)用的技巧,需要的朋友可以參考下2014-12-12C#實(shí)現(xiàn)HTTP訪問類HttpHelper的示例詳解
在項(xiàng)目開發(fā)過程中,我們經(jīng)常會(huì)訪問第三方接口,如我們需要接入的第三方接口是Web API,這時(shí)候我們就需要使用HttpHelper調(diào)用遠(yuǎn)程接口了。本文為大家介紹了C#實(shí)現(xiàn)HTTP訪問類HttpHelper的示例代碼,需要的可以參考一下2022-09-09一文搞懂C#實(shí)現(xiàn)讀寫文本文件中的數(shù)據(jù)
這篇文章重點(diǎn)給大家介紹C#實(shí)現(xiàn)讀寫文本文件中的數(shù)據(jù)的一些知識(shí),讀取.txt文件數(shù)據(jù)的實(shí)例代碼及寫入讀取過程完整代碼,感興趣的朋友跟隨小編一起看看吧2021-06-06