Ejemplo n.º 1
0
        public void Test_ToByteArray()
        {
            using (MagickImage image = new MagickImage(MagickColors.Red, 10, 10))
            {
                using (PixelCollection pixels = image.GetPixels())
                {
                    var bytes = pixels.ToByteArray(0, 0, 1, 1, "BGR");
                    Assert.AreEqual(3, bytes.Length);
                    CollectionAssert.AreEqual(new byte[] { 0, 0, 255 }, bytes);

                    bytes = pixels.ToByteArray(0, 0, 1, 1, "BG");
                    Assert.AreEqual(2, bytes.Length);
                    CollectionAssert.AreEqual(new byte[] { 0, 0 }, bytes);
                }
            }
        }
 public static WriteableBitmap ToBitmap(PixelCollection pixels)
 {
     lock (pixels)
     {
         var newBitmap = new WriteableBitmap(
             pixels.Width, pixels.Height, _dpi, _dpi, PixelFormats.Bgra32, null);
         byte[]    pixels1d = pixels.ToByteArray();
         Int32Rect rect     = new Int32Rect(0, 0, pixels.Width, pixels.Height);
         int       stride   = _pixelValues * pixels.Width;
         newBitmap.WritePixels(rect, pixels1d, stride, 0);
         return(newBitmap);
     }
 }