Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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
Image C#4.0在创建位图图像后解锁图像_Image_C# 4.0_Bitmapimage - Fatal编程技术网

Image C#4.0在创建位图图像后解锁图像

Image C#4.0在创建位图图像后解锁图像,image,c#-4.0,bitmapimage,Image,C# 4.0,Bitmapimage,我正在使用以下命令从现有图像创建位图图像: BitmapImage bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(jpegPath, UriKind.Relative); bmp.EndInit(); 完成此操作后,我想从硬盘中删除图像,但它已被锁定。 有没有办法解锁它以便将其删除?JPG仍然设置为应用程序中现有对象的源。尝试将BitmapImage的源设置为其他内容或将其完全删除。或者在内存中创建JPG的副

我正在使用以下命令从现有图像创建位图图像:

BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(jpegPath, UriKind.Relative);
bmp.EndInit();
完成此操作后,我想从硬盘中删除图像,但它已被锁定。
有没有办法解锁它以便将其删除?

JPG仍然设置为应用程序中现有对象的源。尝试将BitmapImage的源设置为其他内容或将其完全删除。或者在内存中创建JPG的副本。

bmp.CacheOption=BitmapCacheOption.OnLoad

这样会将图像完全加载到内存中,并且不会在图像文件上留下锁