The picture is read into memory and display the stream

if (File.Exists("mainbg.png"))//判断当前文件夹下图片是否存在
{
using (FileStream fs = new FileStream("mainbg.png",FileMode.Open))
{
int len = (int)fs.Length;
byte[] buf = new byte[len];
fs.Read(buf, 0, len);
MemoryStream ms = new MemoryStream();
ms.Write(buf,0,len);
splitContainer.Panel2.BackgroundImage = Image.FromStream(ms);
splitContainer.Panel2.BackgroundImageLayout = ImageLayout.Stretch;
}
}

Guess you like

Origin www.cnblogs.com/GY66520/p/12129313.html