Example #1
0
 /// <summary>
 /// Clears the array. Does not update.
 /// </summary>
 /// <param name="backgroundColor">Color to clear with.</param>
 public void clear(ColorArgb backgroundColor)
 {
     if (hasImage)
     {
         _source.VerifyAccess();
         ColorArgb[] c = _pixels;
         for (int i = 0; i < c.Length; i++)
         {
             c[i] = backgroundColor;
         }
     }
 }
Example #2
0
 /// <summary>
 /// Clears the array, then pushes the changes to the underlying bitmap.
 /// </summary>
 /// <param name="backgroundColor">Color to clear with.</param>
 public void clearAndUpdate(ColorArgb backgroundColor)
 {
     clear(backgroundColor);
     update();
 }
Example #3
0
 /// <summary>
 /// Clears the array, then pushes the changes to the underlying bitmap.
 /// </summary>
 /// <param name="color">Color to clear with.</param>
 public void clearAndUpdate(ColorArgb color)
 {
     _bitmap.clearAndUpdate(color);
 }
Example #4
0
        // ReSharper disable ParameterHidesMember
        /// <summary>
        /// Creates the bitmap if none exists, or changes the size of an existing bitmap. Doesn't scale the image, just crops/pads
        /// the edges.
        /// </summary>
        /// <param name="width">Width of the new image.</param>
        /// <param name="height">Height of the new image.</param>
        /// <param name="dpiX">DPI of the image in X direction (if unsure, get from <see cref="UiUtils.getDpi"/> or just use 96).</param>
        /// <param name="dpiY">DPI of the image in Y direction (if unsure, get from <see cref="UiUtils.getDpi"/> or just use 96).</param>
        /// <param name="backgroundColor">Color with which to pad the edges if the new size is bigger than the old.</param>
        /// <returns>The new ImageSource.</returns>
        public WriteableBitmap createOrResize(int width, int height, int dpiX, int dpiY, ColorArgb backgroundColor)
        {
            if (width <= 0 || height <= 0)
            {
                _source = null;
                _pixels = null;
                _width  = 0;
                _height = 0;
                return(null);
            }

            if (_source != null)
            {
                _source.VerifyAccess(); // we don't want to recreate on a new thread
                if (_source.PixelWidth == width && _source.PixelHeight == height)
                {
                    return(_source);
                }
            }


            int oldWidth  = _width;
            int oldHeight = _height;

            ColorArgb[] oldColors = _pixels;
            ColorArgb[] newColors = new ColorArgb[width * height];
            _width  = width;
            _height = height;
            _pixels = newColors;

            // Resizing should keep as much as possible
            if (oldColors == null)
            {
                clear(backgroundColor);
            }
            else
            {
                // Copy old data
                int minWidth  = Math.Min(width, oldWidth);
                int minHeight = Math.Min(height, oldHeight);
                int y         = 0;
                for (; y < minHeight; y++)
                {
                    int x = 0;
                    for (; x < minWidth; x++)
                    {
                        int oldIndex = (y * oldWidth) + x;
                        int newIndex = (y * width) + x;
                        newColors[newIndex] = oldColors[oldIndex];
                    }
                    for (; x < width; x++)
                    {
                        int newIndex = (y * width) + x;
                        newColors[newIndex] = backgroundColor;
                    }
                }

                // Set the rest to the background color
                for (; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        int newIndex = (y * width) + x;
                        newColors[newIndex] = backgroundColor;
                    }
                }
            }

            _source = new WriteableBitmap(width, height, dpiX, dpiY, PixelFormats.Bgra32, null);
            update();
            return(_source);
        }
Example #5
0
 /// <summary>
 /// Clears the array. Does not update.
 /// </summary>
 /// <param name="color">Color to clear with.</param>
 public void clear(ColorArgb color)
 {
     _bitmap.clear(color);
 }