C#中如何打开图片文件
在C#中如何用代码打开本地计算机上的图片文件,然后把这张打开的图片放在窗体上某个picturebox中?一定是用代码实现才可以,谁能实现,帮一下忙了,急用,先谢谢了!...
在C#中如何用代码打开本地计算机上的图片文件,然后把这张打开的图片放在窗体上某个picturebox中?一定是用代码实现才可以,谁能实现,帮一下忙了,急用,先谢谢了!
展开
3个回答
展开全部
这需要一个按钮,openFileDialog1控件 ,picturebox控件(base_student_picture)
private void button14_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "图片文件(*.jpg)|*.jpg|所有文件|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
base_student_picture.ImageLocation = openFileDialog1.FileName;
path = base_student_id.Text.Trim()+Path.GetExtension(openFileDialog1.FileName);
//MessageBox.Show(path.ToString());
if (File.Exists(Application.StartupPath + "\\image\\" + path))
{
File.Delete(Application.StartupPath + "\\image\\" + path);
File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\image\\" + path);
}
else
{
File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\image\\" + path);
}
}
}
这样是将你在任何盘上的图片都考到你的bin文件夹下的debug文件夹下面了,你先试试!
private void button14_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "图片文件(*.jpg)|*.jpg|所有文件|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
base_student_picture.ImageLocation = openFileDialog1.FileName;
path = base_student_id.Text.Trim()+Path.GetExtension(openFileDialog1.FileName);
//MessageBox.Show(path.ToString());
if (File.Exists(Application.StartupPath + "\\image\\" + path))
{
File.Delete(Application.StartupPath + "\\image\\" + path);
File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\image\\" + path);
}
else
{
File.Copy(openFileDialog1.FileName, Application.StartupPath + "\\image\\" + path);
}
}
}
这样是将你在任何盘上的图片都考到你的bin文件夹下的debug文件夹下面了,你先试试!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using (OpenFileDialog lvse = new OpenFileDialog())
{
lvse.Title = "选择图片";
lvse.InitialDirectory = "";
lvse.Filter = "图片文件|*.bmp;*.jpg;*.jpeg;*.gif;*.png";
lvse.FilterIndex = 1;
if (lvse.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(lvse.FileName);
}
}
{
lvse.Title = "选择图片";
lvse.InitialDirectory = "";
lvse.Filter = "图片文件|*.bmp;*.jpg;*.jpeg;*.gif;*.png";
lvse.FilterIndex = 1;
if (lvse.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(lvse.FileName);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
OpenFileDialog openFile = new OpenFileDialog();
if (openFile.ShowDialog() == DialogResult.OK)
{
string path = openFile.FileName;
Image image = Image.FromFile(path);
this.pictureBox1.Image = image;
}
if (openFile.ShowDialog() == DialogResult.OK)
{
string path = openFile.FileName;
Image image = Image.FromFile(path);
this.pictureBox1.Image = image;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询