Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#清除位图图像或其实例_C#_Wpf_Bitmapimage - Fatal编程技术网

C#清除位图图像或其实例

C#清除位图图像或其实例,c#,wpf,bitmapimage,C#,Wpf,Bitmapimage,我想清除位图图像。我两个都试过了 uploadImage.Source = null; 及 这是我用来制作图像的代码: // BitmapImage.UriSource must be in a BeginInit/EndInit block BitmapImage myBitmapImage = new BitmapImage(); string curItem = destinationFolder + "\\" + listBox1.SelectedItem.ToString(); m

我想清除位图图像。我两个都试过了

uploadImage.Source = null;

这是我用来制作图像的代码:

// BitmapImage.UriSource must be in a BeginInit/EndInit block
BitmapImage myBitmapImage = new BitmapImage();
string curItem = destinationFolder + "\\" + listBox1.SelectedItem.ToString();

myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@curItem);
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
uploadImage.Source = myBitmapImage;

uploadImage.Source=null应该这样做。如何检查源属性的值?我建议。

如果您依赖于屏幕上显示的内容,则由于未通知属性更改,这可能是错误的。尝试为映像创建DependencyProperty属性或通过INotifyPropertyChanged接口发出通知的常规属性。

什么类型是
uploadImage
?可能它有一个
.Clear()
方法?uploadImage是Image类型。没有Clear()方法。
// BitmapImage.UriSource must be in a BeginInit/EndInit block
BitmapImage myBitmapImage = new BitmapImage();
string curItem = destinationFolder + "\\" + listBox1.SelectedItem.ToString();

myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@curItem);
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
uploadImage.Source = myBitmapImage;