Exemple #1
0
        public void WritableBitmapShouldBeUsable(PixelFormat fmt)
        {
            var writableBitmap = new WritableBitmap(256, 256, fmt);

            var data = new int[256 * 256];

            for (int y = 0; y < 256; y++)
            {
                for (int x = 0; x < 256; x++)
                {
                    data[y * 256 + x] = (int)((uint)(x + (y << 8)) | 0xFF000000u);
                }
            }


            using (var l = writableBitmap.Lock())
            {
                for (var r = 0; r < 256; r++)
                {
                    Marshal.Copy(data, r * 256, new IntPtr(l.Address.ToInt64() + r * l.RowBytes), 256);
                }
            }


            var name = nameof(WritableBitmapShouldBeUsable) + "_" + fmt;

            writableBitmap.Save(System.IO.Path.Combine(OutputPath, name + ".out.png"));
            CompareImages(name);
        }
Exemple #2
0
 public override void Render(DrawingContext context)
 {
     if (_lastFrame != null)
     {
         var fmt = (PixelFormat)_lastFrame.Format;
         if (_bitmap == null || _bitmap.PixelWidth != _lastFrame.Width ||
             _bitmap.PixelHeight != _lastFrame.Height)
         {
             _bitmap = new WritableBitmap(_lastFrame.Width, _lastFrame.Height, fmt);
         }
         using (var l = _bitmap.Lock())
         {
             var lineLen = (fmt == PixelFormat.Rgb565 ? 2 : 4) * _lastFrame.Width;
             for (var y = 0; y < _lastFrame.Height; y++)
             {
                 Marshal.Copy(_lastFrame.Data, y * _lastFrame.Stride,
                              new IntPtr(l.Address.ToInt64() + l.RowBytes * y), lineLen);
             }
         }
         context.DrawImage(_bitmap, 1, new Rect(0, 0, _bitmap.PixelWidth, _bitmap.PixelHeight),
                           new Rect(Bounds.Size));
     }
     base.Render(context);
 }