Ejemplo n.º 1
0
        public static MemoryStream ToBitmapStream(WriteableBitmap bitmap)
        {
            var stream = new MemoryStream();

            int width  = bitmap.PixelWidth;
            int height = bitmap.PixelHeight;

            var ei = new EditableImage(width, height);

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int pixel = bitmap.Pixels[(i * width) + j];
                    ei.SetPixel(j, i,
                                (byte)((pixel >> 16) & 0xFF),
                                (byte)((pixel >> 8) & 0xFF),
                                (byte)(pixel & 0xFF),
                                (byte)((pixel >> 24) & 0xFF)
                                );
                }
            }
            Stream png   = ei.GetStream();
            var    len   = (int)png.Length;
            var    bytes = new byte[len];

            png.Read(bytes, 0, len);
            stream.Write(bytes, 0, len);

            return(stream);
        }
Ejemplo n.º 2
0
        public static MemoryStream ToBitmapStream(WriteableBitmap bitmap)
        {
            var stream = new MemoryStream();

            int width = bitmap.PixelWidth;
            int height = bitmap.PixelHeight;

            var ei = new EditableImage(width, height);

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int pixel = bitmap.Pixels[(i * width) + j];
                    ei.SetPixel(j, i,
                                (byte)((pixel >> 16) & 0xFF),
                                (byte)((pixel >> 8) & 0xFF),
                                (byte)(pixel & 0xFF),
                                (byte)((pixel >> 24) & 0xFF)
                        );
                }
            }
            Stream png = ei.GetStream();
            var len = (int)png.Length;
            var bytes = new byte[len];
            png.Read(bytes, 0, len);
            stream.Write(bytes, 0, len);

            return stream;
        }