Ejemplo n.º 1
0
        private unsafe void ChangeRandomBgColorPixel()
        {
            using (BitmapBuffer buffer = randomBgSoftwareBitmap.LockBuffer(BitmapBufferAccessMode.Write))
            {
                using (var reference = buffer.CreateReference())
                {
                    byte *dataInBytes;
                    uint  capacity;
                    ((IMemoryBufferByteAccess)reference).GetBuffer(out dataInBytes, out capacity);

                    // Fill-in the BGRA plane
                    BitmapPlaneDescription bufferLayout = buffer.GetPlaneDescription(0);
                    double imgWidth  = bufferLayout.Width;
                    double imgHeight = bufferLayout.Height;

                    for (int row = 0; row < imgHeight; row++)
                    {
                        for (int col = 0; col < imgWidth; col++)
                        {
                            double   hue   = col * (360 / imgWidth);
                            HSVColor hsv   = new HSVColor(hue, 1.0, 1.0);
                            Color    color = hsv.GetRGB();

                            int pixelIndex = bufferLayout.Stride * row + 4 * col;
                            if (dataInBytes[pixelIndex + 3] != 0)
                            {
                                dataInBytes[pixelIndex + 0] = (byte)color.B;
                                dataInBytes[pixelIndex + 1] = (byte)color.G;
                                dataInBytes[pixelIndex + 2] = (byte)color.R;
                            }
                        }
                    }
                }
            }
        }