C#将Bitmap图像转换为BitmapImage
public void InitImage(Bitmap bitmap)
{
try
{
// 将Bitmap转换为WPF的BitmapImage
BitmapImage bitmapImage;
using (MemoryStream memory = new MemoryStream())
{
bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
memory.Position = 0;
bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
}
Image_Img.Source = bitmapImage;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

浙公网安备 33010602011771号