1、从项目资源文件中加载图片,首先将图片添加到项目资源中(工程项目下-Properties 下双击Resources.resx进行添加资源)
this.pictureBox1.Image = xxx.Properties.Resources.Penguins;
2、从窗体资源文件中加载图片 …- 前提需要先在窗体路径下找到资源文件(后缀为.resx)双击然后将图片添加进去。
System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(Form1));
this.pictureBox1.Image =(Bitmap)rm.Getobject("xxx");
3、加载本地图片,使用lmage.FromFile()加载计算机中的图片
//取得程序当前所在路径,这点很重要
string appPath= system.Windows.Forms.Application.startupPath;
//仅级当留片存在时才趣载图片
if(System.I0.File.Exists(appPath + @"\xxx.jpg"))//图片需跟exe同一路径下
Image img = Image.FromFile(appPath + @"\xxx.jpg");this.pictureBoxl.Image = img;
4、加载网络图片,当网络比较慢,加载时间长时可看到设置的Initiallmage的效果。
//通过ImageLocation设置网络留片
this.pictureBox1.ImageLocation = "https://xxx/xxx.jpg";