Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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());
            }
        }