c# Picturebox路径
作者:互联网
picHeadImg.ImageLocation = string.Format("http://img3.imgtn.bdimg.com/it/u=4160106393,1595591376&fm=214&gp=0.jpg");
// picHeadImg.Image = Image.FromStream(WebRequest.Create(head_img).GetResponse().GetResponseStream());
picHeadImg.Image = Properties.Resources.DefulatHeadImg;
picHeadImg.Load(pathname)
1.绝对路径:
this.pictureBox.Image=Image.FromFile("C:\\test.jpg");
2.相对路径:
Application.StartupPath;
可以得到程序根目录
this.pictureBox.Image=Image.FromFile(Application.StartupPath "\\test.jpg");
3.获得网络图片的路径
string url="http://img.zcool.cn/community/01635d571ed29832f875a3994c7836.png@900w_1l_2o_100sh.jpg";
this.pictureBox.Image= Image.FromStream(System.Net.WebRequest.Create(url).GetResponse().GetResponseStream());
//保存
SaveFileDialog save = new SaveFileDialog(); save.ShowDialog(); if (save.FileName != string.Empty) { picHeadImg.Image.Save(save.FileName); }
//异步加载图像,加载txtURI的图像 pictureBox1.LoadAsync(txtURI.Text);
private void pictureBox1_LoadProgressChanged(object sender, ProgressChangedEventArgs e)
{
//显示进度
this.lblMsg.Text = string.Format("当前进度:{0}.", e.ProgressPercentage);
}
private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
//加载错误处理事件
if (e.Error != null)
{
lblMsg.Text = "错误信息:" + e.Error.Message;
return;
}
//如果取消
if (e.Cancelled)
{
lblMsg.Text = "操作被取消。";
}
else
{
lblMsg.Text = "加载完成.";
}
button1.Enabled = true;
}
标签:lblMsg,c#,Text,Image,路径,jpg,Picturebox,picHeadImg,save 来源: https://www.cnblogs.com/ruiyuan/p/11445739.html