Esempio n. 1
0
        /// <summary>
        /// Gets the color of the pixel at the x, y coordinate as a Color struct.
        /// </summary>
        /// <param name="bmp">The WriteableBitmap.</param>
        /// <param name="x">The x coordinate of the pixel.</param>
        /// <param name="y">The y coordinate of the pixel.</param>
        /// <returns>The color of the pixel at x, y as a Color struct.</returns>
        public Color GetPixel(int x, int y)
        {
            int  c = GetPixels()[y * _width + x];
            byte a = (byte)(c >> 24);
            //float ai = a / PreMultiplyFactor;
            float ai = 1;

            return(Color.FromArgb(a, (byte)((c >> 16) * ai), (byte)((c >> 8) * ai), (byte)(c * ai)));
        }
Esempio n. 2
0
        /// <summary>
        /// Fills the whole WriteableBitmap with a color.
        /// </summary>
        /// <param name="bmp">The WriteableBitmap.</param>
        /// <param name="color">The color used for filling.</param>
        public void Clear(Color color)
        {
            float ai = color.A * PreMultiplyFactor;
            int col = (color.A << 24) | ((byte)(color.R * ai) << 16) | ((byte)(color.G * ai) << 8) | (byte)(color.B * ai);
            int[] pixels = GetPixels();
            int w = _inner.PixelWidth;
            int h = _inner.PixelHeight;
            int len = w * SizeOfARGB;

            // Fill first line
            for (int x = 0; x < w; x++)
            {
                pixels[x] = col;
            }

            // Copy first line
            for (int y = 1; y < h; y++)
            {
                Buffer.BlockCopy(pixels, 0, pixels, y * len, len);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Fills the whole WriteableBitmap with a color.
        /// </summary>
        /// <param name="bmp">The WriteableBitmap.</param>
        /// <param name="color">The color used for filling.</param>
        public void Clear(Color color)
        {
            float ai  = color.A * PreMultiplyFactor;
            int   col = (color.A << 24) | ((byte)(color.R * ai) << 16) | ((byte)(color.G * ai) << 8) | (byte)(color.B * ai);

            int[] pixels = GetPixels();
            int   w      = _inner.PixelWidth;
            int   h      = _inner.PixelHeight;
            int   len    = w * SizeOfARGB;

            // Fill first line
            for (int x = 0; x < w; x++)
            {
                pixels[x] = col;
            }

            // Copy first line
            for (int y = 1; y < h; y++)
            {
                Buffer.BlockCopy(pixels, 0, pixels, y * len, len);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Sets the color of the pixel.
 /// </summary>
 /// <param name="x">The x coordinate (row).</param>
 /// <param name="y">The y coordinate (column).</param>
 /// <param name="color">The color.</param>
 public void SetPixel(int x, int y, Color color)
 {
     float ai = color.A * PreMultiplyFactor;
     GetPixels()[y * _width + x] = (color.A << 24) | ((byte)(color.R * ai) << 16) | ((byte)(color.G * ai) << 8) | (byte)(color.B * ai);
 }
Esempio n. 5
0
        /// <summary>
        /// Sets the color of the pixel.
        /// </summary>
        /// <param name="x">The x coordinate (row).</param>
        /// <param name="y">The y coordinate (column).</param>
        /// <param name="color">The color.</param>
        public void SetPixel(int x, int y, Color color)
        {
            float ai = color.A * PreMultiplyFactor;

            GetPixels()[y * _width + x] = (color.A << 24) | ((byte)(color.R * ai) << 16) | ((byte)(color.G * ai) << 8) | (byte)(color.B * ai);
        }