C#圖片保存在指定位置或者自選位置 And C# 打開以對話框,獲取文件夾路徑 、文件的路徑、文件名


在引用的地方引用一下using System.Drawing;程序集

1.保存在指定位置  列:image.save("存放的地址路徑")

  private void button1_Click(object sender, EventArgs e)
{ 
    //第一種
    int b=0;
  Bitmap bitmap2 = new Bitmap(pictureBox1.Image);
          
  bitmap2.Save(@"C:\Users\lenovo\Pictures\npm\" + b + ".png");
    //第二種
  Image image= pictureBox1.Image;

  image.Save(@"C:\Users\lenovo\Pictures\npm\" + b + ".png");
    b++
}

 2.將此 Image 以指定格式保存到指定文件。列:image.save("地址路徑","格式")

  private void button1_Click(object sender, EventArgs e)
{ 
    //第一種
    int b=0;
  Bitmap bitmap2 = new Bitmap(pictureBox1.Image);
          
  bitmap2.Save(@"C:\Users\lenovo\Pictures\npm\" ,ImageFormat.Png);
    //第二種
  Image image= pictureBox1.Image;

  image.Save(@"C:\Users\lenovo\Pictures\npm\" ,ImageFormat.Bmp);
    b++
}

3.使用指定的編碼器和圖像編碼器參數,將該圖像保存到指定的流。

4.將此圖像以指定的格式保存到指定的流中。  

3and4可以去微軟官方Api看看有詳細的實例        微軟官方API Image.Save Method 

 

打開的文件夾或者文件夾名下的文件

// 獲取文件夾絕對路徑    顯示在 txtbox 控件里

System.Windows.Forms.FolderBrowserDialog folder =

  new System.Windows.Forms.FolderBrowserDialog();

if (folder.ShowDialog() == DialogResult.OK)
{
  this.txtboxPath.Text = folder.SelectedPath;              

  }

// 獲取文件和路徑名 一起顯示在 txtbox 控件里

OpenFileDialog dialog = new OpenFileDialog();
if (dialog .ShowDialog() == DialogResult.OK)
{
  this.txtboxPath.SelectedText = dialog.FileName;                   

}

 //如果只顯示文件名

OpenFileDialog dialog = new OpenFileDialog();
if (dialog .ShowDialog() == DialogResult.OK)
{
  this.txtboxPath.SelectedText = dialog.SafeFileName;                   

}

//原文鏈接http://www.cnblogs.com/zhangzhu/archive/2013/06/01/3112601.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM