Beispiel #1
0
        public static void PaintOverview(IGraphics g, SizeI2 totalSize, RectangleI2 visibleWin,
                                         Func <int, int, Bitmap2> getOverviewBitmap, float zoomFactorX, float zoomFactorY)
        {
            Size2      overview = CalcOverviewSize(visibleWin.Width, visibleWin.Height, totalSize.Width, totalSize.Height);
            Rectangle2 win      = CalcWin(overview, totalSize, visibleWin, zoomFactorX, zoomFactorY);

            g.FillRectangle(Brushes2.White, 0, visibleWin.Height - overview.Height, overview.Width, overview.Height);
            g.DrawImageUnscaled(getOverviewBitmap((int)overview.Width, (int)overview.Height), 0,
                                visibleWin.Height - overview.Height);
            Brush2 b = new Brush2(Color2.FromArgb(30, 0, 0, 255));

            if (win.X > 0)
            {
                g.FillRectangle(b, 0, visibleWin.Height - overview.Height, win.X, overview.Height);
            }
            if (overview.Width - win.X - win.Width > 0)
            {
                g.FillRectangle(b, win.X + win.Width, visibleWin.Height - overview.Height, overview.Width - win.X - win.Width,
                                overview.Height);
            }
            if (win.Y > 0)
            {
                g.FillRectangle(b, win.X, visibleWin.Height - overview.Height, win.Width, win.Y);
            }
            if (overview.Height - win.Y - win.Height > 0)
            {
                g.FillRectangle(b, win.X, visibleWin.Height - overview.Height + win.Y + win.Height - 1, win.Width,
                                overview.Height - win.Y - win.Height);
            }
            g.DrawRectangle(Pens2.Black, 0, visibleWin.Height - overview.Height - 1, overview.Width, overview.Height);
            g.DrawRectangle(Pens2.Blue, win.X, visibleWin.Height - overview.Height - 1 + win.Y, win.Width, win.Height);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <code>Bitmap2</code> class from the specified data stream.
        /// </summary>
        /// <param name="stream">The data stream used to load the image.</param>
        public Bitmap2(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException();
            }
            Image2 im = new Image2(stream);

            data = new int[im.Height, im.Width];
            for (int i = 0; i < im.Pixels.Length; i++)
            {
                Color2 c = im.Pixels[i];
                SetPixel(i % im.Width, i / im.Width, Color2.FromArgb(c.A, c.R, c.G, c.B));
            }
        }
Beispiel #3
0
        public Bitmap2 Lighter()
        {
            Bitmap2 result = new Bitmap2(Width, Height);

            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    int p = GetPixel(i, j);
                    result.SetPixel(i, j,
                                    Color2.FromArgb(Math.Min(255, Color2.GetR(p) + 20), Math.Min(255, Color2.GetG(p) + 20),
                                                    Math.Min(255, Color2.GetB(p) + 20)).Value);
                }
            }
            return(result);
        }
Beispiel #4
0
        public static void PaintOverview(IGraphics g, SizeI2 totalSize, RectangleI2 visibleWin,
                                         Func <int, int, Bitmap2> getOverviewBitmap, float zoomFactorX, float zoomFactorY, bool overviewTopRight)
        {
            if (getOverviewBitmap == null)
            {
                return;
            }
            Size2      overview = CalcOverviewSize(visibleWin.Width, visibleWin.Height, totalSize.Width, totalSize.Height);
            Rectangle2 win      = CalcWin(overview, totalSize, visibleWin, zoomFactorX, zoomFactorY);
            float      xpos     = overviewTopRight ? visibleWin.Width - overview.Width - 1 : 0;
            float      ypos     = overviewTopRight ? 1 : visibleWin.Height - overview.Height;

            g.FillRectangle(Brushes2.White, xpos, ypos, overview.Width, overview.Height);
            Bitmap2 bm = getOverviewBitmap((int)overview.Width, (int)overview.Height);

            if (bm == null)
            {
                return;
            }
            g.DrawImageUnscaled(bm, xpos, ypos);
            Brush2 b = new Brush2(Color2.FromArgb(30, 0, 0, 255));

            if (win.X > 0)
            {
                g.FillRectangle(b, xpos, ypos, win.X, overview.Height);
            }
            if (overview.Width - win.X - win.Width > 0)
            {
                g.FillRectangle(b, xpos + win.X + win.Width, ypos, overview.Width - win.X - win.Width, overview.Height);
            }
            if (win.Y > 0)
            {
                g.FillRectangle(b, xpos + win.X, ypos, win.Width, win.Y);
            }
            if (overview.Height - win.Y - win.Height > 0)
            {
                g.FillRectangle(b, xpos + win.X, ypos + win.Y + win.Height - 1, win.Width, overview.Height - win.Y - win.Height);
            }
            g.DrawRectangle(Pens2.Black, xpos, ypos - 1, overview.Width, overview.Height);
            g.DrawRectangle(Pens2.Blue, xpos + win.X, ypos - 1 + win.Y, win.Width, win.Height);
            if (win.Width < 5 && win.Height < 5)
            {
                g.DrawLine(Pens2.Red, xpos + win.X, ypos + win.Y, xpos + win.X + 5, ypos + win.Y);
                g.DrawLine(Pens2.Red, xpos + win.X, ypos + win.Y, xpos + win.X, ypos + win.Y + 5);
                g.DrawLine(Pens2.Red, xpos + win.X, ypos + win.Y, xpos + win.X + 7, ypos + win.Y + 7);
            }
        }
Beispiel #5
0
        private static Color2 Average(IList <Color2> colors, IList <float> weights)
        {
            float r    = 0;
            float g    = 0;
            float b    = 0;
            float norm = 0;

            for (int i = 0; i < colors.Count; i++)
            {
                Color2 col = colors[i];
                float  w   = weights[i];
                r    += col.R * w;
                g    += col.G * w;
                b    += col.B * w;
                norm += w;
            }
            Color2 x = Color2.FromArgb(255, (int)Math.Round(r / norm), (int)Math.Round(g / norm), (int)Math.Round(b / norm));

            return(x);
        }
Beispiel #6
0
        public static void FillShadedRectangle(Bitmap2 b, int w, int h)
        {
            b.FillRectangle(Color2.White, 0, 0, w - 1, h - 1);
            b.SetPixel(1, 1, Color2.FromArgb(230, 238, 252));
            b.SetPixel(1, h - 3, Color2.FromArgb(219, 227, 248));
            b.SetPixel(w - 3, 1, Color2.FromArgb(220, 230, 249));
            b.SetPixel(w - 3, h - 3, Color2.FromArgb(217, 227, 246));
            b.SetPixel(w - 1, h - 3, Color2.FromArgb(174, 192, 214));
            b.SetPixel(w - 2, h - 2, Color2.FromArgb(174, 196, 219));
            b.SetPixel(0, h - 2, Color2.FromArgb(195, 212, 231));
            b.SetPixel(0, h - 1, Color2.FromArgb(237, 241, 243));
            b.SetPixel(w - 2, h - 1, Color2.FromArgb(236, 242, 247));
            b.SetPixel(w - 1, h - 1, Color2.FromArgb(255, 255, 255));
            b.SetPixel(w - 1, h - 2, Color2.FromArgb(255, 255, 255));
            int wi = w - 5;
            int he = h - 5;

            int[][] upper = InterpolateRgb(225, 234, 254, 188, 206, 250, wi);
            int[][] lower = InterpolateRgb(183, 203, 249, 174, 200, 247, wi);
            for (int i = 0; i < wi; i++)
            {
                int[][] pix = InterpolateRgb(upper[0][i], upper[1][i], upper[2][i], lower[0][i], lower[1][i], lower[2][i], he);
                for (int j = 0; j < he; j++)
                {
                    b.SetPixel(i + 2, j + 2, Color2.FromArgb(pix[0][j], pix[1][j], pix[2][j]));
                }
            }
            int[][] pix2 = InterpolateRgb(208, 223, 252, 170, 192, 243, he);
            for (int j = 0; j < he; j++)
            {
                b.SetPixel(1, j + 2, Color2.FromArgb(pix2[0][j], pix2[1][j], pix2[2][j]));
            }
            pix2 = InterpolateRgb(185, 202, 243, 176, 197, 242, he);
            for (int j = 0; j < he; j++)
            {
                b.SetPixel(w - 3, j + 2, Color2.FromArgb(pix2[0][j], pix2[1][j], pix2[2][j]));
            }
            pix2 = InterpolateRgb(208, 223, 252, 175, 197, 244, wi);
            for (int i = 0; i < wi; i++)
            {
                b.SetPixel(i + 2, 1, Color2.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i]));
            }
            pix2 = InterpolateRgb(183, 198, 241, 176, 196, 242, wi);
            for (int i = 0; i < wi; i++)
            {
                b.SetPixel(i + 2, h - 3, Color2.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i]));
            }
            pix2 = InterpolateRgb(238, 237, 229, 160, 181, 211, he + 2);
            for (int i = 0; i < he + 2; i++)
            {
                b.SetPixel(w - 1, i, Color2.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i]));
            }
            pix2 = InterpolateRgb(170, 192, 225, 126, 159, 211, w / 2);
            for (int i = 1; i <= w / 2; i++)
            {
                b.SetPixel(i, h - 1, Color2.FromArgb(pix2[0][i - 1], pix2[1][i - 1], pix2[2][i - 1]));
            }
            pix2 = InterpolateRgb(126, 159, 211, 148, 176, 221, w - 3 - w / 2);
            for (int i = w / 2 + 1; i <= w - 3; i++)
            {
                b.SetPixel(i, h - 1, Color2.FromArgb(pix2[0][i - w / 2 - 1], pix2[1][i - w / 2 - 1], pix2[2][i - w / 2 - 1]));
            }
        }