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.效果如圖所示