1.C#将Bitmap图像转换为BitmapImage,并给Image控件显示图像后台实现
public void InitImage(Bitmap bitmap){try{// 将Bitmap转换为WPF的BitmapImageBitmapImage 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);}}
2.效果如图所示