先前使用winform时,给picturebox加载了图片image1,之后修改为image2,只要是通过数据流得方式读取图片得,就可以将image1删除,代码如下:
filestream fs=new filestream("a.jpg",filemode.open,fileacess.read);
picturebox.image=image.fromstream(fs);
fs.close(); 只要将数据流关闭了,就可以删除image1。但是在wpf中得image不是这样得,必须把流存储到字节数组中,才可以删除。代码如下: filestream fs=new filestream("a.jpg",filemode.open,fileacess.read);picturebox.image=image.fromstream(fs);
byte[] bytes=new byte((int)fs.length);
fs.Read(bytes, 0, bytes.Length);
fs.close();image.source=bytes;可能是因为picturebox跟image控件存储图片得方式不一样,一个是直接存储,一个是绑定。