如何在picturebox 中添加图片代码 C# 要使用Button控件的
2个回答
展开全部
你可以如下写
private void button1_Click(object sender, EventArgs e)
{
this.pictureBox1.Image = Image.FromFile(@"..\..\picture.jpg");//引号中填图像的绝对或相对路径
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;//这里设置图像的现实模式,有很多种,可以自己试一下,这里用的是缩放模式
}
private void button1_Click(object sender, EventArgs e)
{
this.pictureBox1.Image = Image.FromFile(@"..\..\picture.jpg");//引号中填图像的绝对或相对路径
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;//这里设置图像的现实模式,有很多种,可以自己试一下,这里用的是缩放模式
}
展开全部
private void button3_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
//openFileDialog1.InitialDirectory = "D:\\";
openFileDialog1.Filter = "*jpg|*.JPG|*.GIF|*.GIF|*.BMP|*.BMP";
if (openFileDialog1.ShowDialog()==DialogResult.OK)
{
string filename = openFileDialog1.FileName;
pictureBox1.Image = new Bitmap(filename);
string path = AppDomain.CurrentDomain.BaseDirectory;
string name = filename.Substring(filename.LastIndexOf('\\'));
if (!Directory.Exists(path + "images\\"))
{
Directory.CreateDirectory(path + "images\\");
}
File.Copy(filename, path + "images\\" + name,true);//出错。当出现相同命名的图片时候报错!
}
}
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
//openFileDialog1.InitialDirectory = "D:\\";
openFileDialog1.Filter = "*jpg|*.JPG|*.GIF|*.GIF|*.BMP|*.BMP";
if (openFileDialog1.ShowDialog()==DialogResult.OK)
{
string filename = openFileDialog1.FileName;
pictureBox1.Image = new Bitmap(filename);
string path = AppDomain.CurrentDomain.BaseDirectory;
string name = filename.Substring(filename.LastIndexOf('\\'));
if (!Directory.Exists(path + "images\\"))
{
Directory.CreateDirectory(path + "images\\");
}
File.Copy(filename, path + "images\\" + name,true);//出错。当出现相同命名的图片时候报错!
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询