private static IImage GetEmptyBitmap() { var writeableBitmap = new WriteableBitmap(10, 10, 96, 96, PixelFormats.Bgr24, new BitmapPalette(new List <Color> { Color.FromRgb(0, 0, 0) })); var bmpSrc = Extensions.ConvertWriteableBitmapToBitmapImage(writeableBitmap); Bgra <byte>[,] colorImg = bmpSrc.ToArray <Bgra <byte> >(); return(colorImg.Lock()); }
public static IImage ToBitmapImage(this Bitmap bitmap) { using (var stream = new MemoryStream()) { bitmap.Save(stream, ImageFormat.Bmp); stream.Position = 0; BitmapImage result = new BitmapImage(); result.BeginInit(); // According to MSDN, "The default OnDemand cache option retains access to the stream until the image is needed." // Force the bitmap to load right now so we can dispose the stream. result.CacheOption = BitmapCacheOption.OnLoad; result.StreamSource = stream; result.EndInit(); result.Freeze(); Bgra <byte>[,] colorImg = result.ToArray <Bgra <byte> >(); return(colorImg.Lock()); } }