一、后台屬性
1、pictureBox1.Image顯示圖片
2、pictureBox1.ImageLocation存儲和提取圖片路徑
二、面板屬性
1、Picturebox控件SizeMode屬性
(1)Normal模式:如果圖片大於Picturebox控件大小,圖片不能完全顯示
(2)AutoSize:自動調整Picturebox控件大小去適應圖片的大小,圖片可以完全顯示。
(3)StretchImage:Picturebox控件大小不變,自動調整圖像適應控件。
三、在本機電腦中選擇圖片並顯示在pictureBox1中
OpenFileDialog openFileDialog = new OpenFileDialog();
//獲取或設置當前文件名篩選器字符串,該字符串決定對話框的"另存為文件類型"或"文件類型"框中出現的選擇內容
openFileDialog.Filter = "Files|*.jpg;*.jpeg;*.png;*.gif";
//獲取文件對話框中的初始目錄(圖片路徑)
openFileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
openFileDialog.FileName; //獲取圖片路徑
System.Drawing.Image img = System.Drawing.Image.FromFile(openFileDialog.FileName);
System.Drawing.Image bmp = new System.Drawing.Bitmap(img);
img.Dispose();
pictureBox1.Image = bmp;
this.pictureBox1.ImageLocation= openFileDialog.FileName;
}
四、將pictureBox里的圖片另存
private void button2_Click(object sender, EventArgs e) //保存方法
{
SaveFileDialog save = new SaveFileDialog();
save.ShowDialog();
if (save.FileName != string.Empty)
{
pictureBox1.Image.Save(save.FileName);
}
}
