public void Draw(
            )
        {
            AHSL hsl;
            int  width  = (int)imgBorder.ActualWidth;
            int  height = (int)imgBorder.ActualHeight;

#if !SILVERLIGHT
            int[] pixels = new int[width * height];
#endif
            var bitmap = Compat.CreateBitmap(width, height);

            for (int x = 0; x < width; ++x)
            {
                for (int y = 0; y < height; ++y)
                {
                    hsl = new AHSL(x / (width / 360.0), Saturation, 1.0 - (((double)y) / height), 1.0);
#if !SILVERLIGHT
                    pixels[y * width + x] = hsl.Double().ToARGB32();
#else
                    bitmap.Pixels[y * width + x] = hsl.Double().ToARGB32();
#endif
                }
            }
#if !SILVERLIGHT
            bitmap.WritePixels(new Int32Rect(0, 0, width, height), pixels, Compat.GetBitmapStride(width), 0);
#endif
            spectrum.Height = height;
            spectrum.Width  = width;

            spectrum.Source = bitmap;
        }
示例#2
0
        public void Draw(
            )
        {
            AHSB hsb;
            int  width  = (int)imgBorder.ActualWidth;
            int  height = (int)imgBorder.ActualHeight;

#if !SILVERLIGHT
            int[] pixels = new int[width * height];
#endif
            var brisatBitmap = Compat.CreateBitmap(width, height);

            for (int x = 0; x < width; ++x)
            {
                int col = x / 6;
                for (int y = 0; y < height; ++y)
                {
                    int   row = y / 6;
                    Color c   = Colors.Red;

                    if (col % 2 == 0 && row % 2 == 0)
                    {
                        c = Colors.Red;
                    }
                    else if (col % 2 == 0 && row % 2 == 1)
                    {
                        c = Colors.Blue;
                    }
                    else if (col % 2 == 1 && row % 2 == 1)
                    {
                        c = Colors.Green;
                    }
                    else
                    {
                        c = Colors.Yellow;
                    }

                    hsb            = c.Double().ToAHSB();
                    hsb.Saturation = x / (double)width;
                    hsb.Brightness = 1.0 - y / (double)height;

#if !SILVERLIGHT
                    pixels[y * width + x] = hsb.Double().ToARGB32();
#else
                    brisatBitmap.Pixels[y * width + x] = hsb.Double().ToARGB32();
#endif
                }
            }
#if !SILVERLIGHT
            brisatBitmap.WritePixels(new Int32Rect(0, 0, width, height), pixels, Compat.GetBitmapStride(width), 0);
#endif
            brisat.Height = height;
            brisat.Width  = width;

            brisat.Source = brisatBitmap;
        }
        public void UpdateImageBitmap(
            )
        {
            Border border;

#if !SILVERLIGHT
            int[] pixels;
#endif
            border = this.Orientation == Orientation.Horizontal ? m_horzImageBorder : m_vertImageBorder;

            if (border != null &&
                m_calc != null &&
                border.ActualHeight != 0 &&
                border.ActualWidth != 0)
            {
                int width  = (int)Math.Floor(border.ActualWidth);
                int height = (int)Math.Floor(border.ActualHeight);

                m_bitmap = Compat.CreateBitmap(width, height);
#if !SILVERLIGHT
                pixels = new int[width * height];
#endif
                for (int x = 0; x < width; ++x)
                {
                    for (int y = 0; y < height; ++y)
                    {
                        int pixValue = 0;

                        if (this.Orientation == Orientation.Horizontal)
                        {
                            pixValue = m_calc((this.Maximum / width) * x).ToARGB32();;
                        }
                        else
                        {
                            pixValue = m_calc((this.Maximum / height) * y).ToARGB32();;
                        }
#if SILVERLIGHT
                        m_bitmap.Pixels[y * width + x] = pixValue;
#else
                        pixels[y * width + x] = pixValue;
#endif
                    }
                }
#if !SILVERLIGHT
                m_bitmap.WritePixels(new Int32Rect(0, 0, width, height), pixels, Compat.GetBitmapStride(width), 0);
#endif
                border.Background = new ImageBrush()
                {
                    ImageSource = m_bitmap
                };
            }
        }
        ///
        /// <summary>
        /// Draw color wheel</summary>
        ///
        protected void Redraw(
            )
        {
            int             radius = (int)(wheelRoot.ActualHeight / 2);
            WriteableBitmap bm;
            double          sectorWidth = SectorWidth;
            ColorWheelBase  wl;

            DateTime d = DateTime.Now;

            wl = Wheel ?? new RYGBColorWheel();
            bm = Compat.CreateBitmap(radius * 2, radius * 2);

#if !SILVERLIGHT
            Int32[] pixels = new Int32[radius * 2 * radius * 2];
#endif
            for (double x = -radius; x < radius; x++)
            {
                int height = (int)Math.Sqrt(radius * radius - x * x);

                for (double y = -height; y < height; y++)
                {
                    int    offset;
                    double degree;
                    var    val = GetColorFromPoint(radius, x, y, wl, out offset, out degree);
#if SILVERLIGHT
                    bm.Pixels[offset] = val;
#else
                    pixels[offset] = val;
#endif
                }
            }

#if !SILVERLIGHT
            bm.WritePixels(new Int32Rect(0, 0, radius * 2, radius * 2), pixels, Compat.GetBitmapStride(radius * 2), 0);
#endif
            wheel.Source = bm;
            DrawPointers();

            Debug.WriteLine("ColorWheelControl.Redraw: " + (DateTime.Now - d).TotalMilliseconds);
        }