Exemplo n.º 1
0
        public void WritePixelBufferBitmap()
        {
            using (Bitmap bitmap = new Bitmap(1, 1))
                using (GraphicsWindow window = Device.CreateWindow(1, 1))
                    using (WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream,
                                                                                        BitmapAlgorithms.SizeOfPixelsInBytes(bitmap)))
                    {
                        Color color = Color.FromArgb(0, 1, 2, 3);
                        bitmap.SetPixel(0, 0, color);

                        pixelBuffer.CopyFromBitmap(bitmap);

                        //
                        // Verify read back - comes back BGRA
                        //
                        BlittableBGRA[] readBackPixel = pixelBuffer.CopyToSystemMemory <BlittableBGRA>();
                        Assert.AreEqual(color.R, readBackPixel[0].R);
                        Assert.AreEqual(color.G, readBackPixel[0].G);
                        Assert.AreEqual(color.B, readBackPixel[0].B);
                        Assert.AreEqual(color.A, readBackPixel[0].A);

                        //
                        // Verify read back into bitmap
                        //
                        using (Bitmap readBackBitmap = pixelBuffer.CopyToBitmap(1, 1, PixelFormat.Format32bppArgb))
                        {
                            Assert.AreEqual(color, readBackBitmap.GetPixel(0, 0));
                        }
                    }
        }
Exemplo n.º 2
0
        public void WritePixelBuffer()
        {
            BlittableRGBA[] pixels = new BlittableRGBA[]
            {
                new BlittableRGBA(Color.Red),
                new BlittableRGBA(Color.Green),
                new BlittableRGBA(Color.Blue),
                new BlittableRGBA(Color.White)
            };
            int sizeInBytes = ArraySizeInBytes.Size(pixels);

            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream, sizeInBytes))
                {
                    //
                    // Verify creating pixel buffer
                    //
                    Assert.IsNotNull(pixelBuffer);
                    Assert.AreEqual(PixelBufferHint.Stream, pixelBuffer.UsageHint);
                    Assert.AreEqual(sizeInBytes, pixelBuffer.SizeInBytes);

                    //
                    // Verify copying entire buffer between system memory and pixel buffer
                    //
                    pixelBuffer.CopyFromSystemMemory(pixels);

                    BlittableRGBA[] pixels2 = pixelBuffer.CopyToSystemMemory <BlittableRGBA>(0, pixelBuffer.SizeInBytes);
                    Assert.AreEqual(pixels[0], pixels2[0]);
                    Assert.AreEqual(pixels[1], pixels2[1]);
                    Assert.AreEqual(pixels[2], pixels2[2]);

                    //
                    // Verify modiying a subset of the vertex buffer
                    //
                    BlittableRGBA modifiedPixel = new BlittableRGBA(Color.Black);
                    pixelBuffer.CopyFromSystemMemory(new[] { modifiedPixel }, SizeInBytes <BlittableRGBA> .Value);

                    BlittableRGBA[] pixels3 = pixelBuffer.CopyToSystemMemory <BlittableRGBA>(0, pixelBuffer.SizeInBytes);
                    Assert.AreEqual(pixels[0], pixels3[0]);
                    Assert.AreEqual(modifiedPixel, pixels3[1]);
                    Assert.AreEqual(pixels[2], pixels3[2]);
                }
        }