//释放资源
public static BitmapImage GetImage(string imagePath)
{
BitmapImage bitmap = new BitmapImage();
if (File.Exists(imagePath))
{
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
using (Stream ms = new MemoryStream(File.ReadAllBytes(imagePath)))
{
bitmap.StreamSource = ms;
bitmap.EndInit();
bitmap.Freeze();
}
}
else
{
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
string System_ = System.AppDomain.CurrentDomain.BaseDirectory + "_08Server_Img//Simages//V_02.png";
using (Stream ms = new MemoryStream(File.ReadAllBytes(System_)))
{
bitmap.StreamSource = ms;
bitmap.EndInit();
bitmap.Freeze();
}
}
return bitmap;
}
wpf 图片格式转换
最新推荐文章于 2022-08-20 09:46:00 发布