把图片读取到内存流并显示
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;
}
}