Example #1
0
 public static Bitmap2 GetImage(char c, int width, int height, Color2 fgColor, Color2 bgColor)
 {
     if (height <= 1 || width <= 1) {
         return null;
     }
     Bitmap2 template = GetImage(c);
     if (template == null) {
         return null;
     }
     int twidth = template.Width;
     int theight = template.Height;
     Bitmap2 result = new Bitmap2(width, height);
     for (int i = 0; i < width; i++) {
         float wI1;
         float wI2;
         int indI = CalcInd(i, width, twidth, out wI1, out wI2);
         for (int j = 0; j < height; j++) {
             float wJ1;
             float wJ2;
             int indJ = CalcInd(j, height, theight, out wJ1, out wJ2);
             Color2 ij = IsSet(indI, indJ, template) ? fgColor : bgColor;
             Color2 ipj = IsSet(indI + 1, indJ, template) ? fgColor : bgColor;
             Color2 ijp = IsSet(indI, indJ + 1, template) ? fgColor : bgColor;
             Color2 ipjp = IsSet(indI + 1, indJ + 1, template) ? fgColor : bgColor;
             Color2 col = Average(new[] { ij, ipj, ijp, ipjp }, new[] { wI1 * wJ1, wI2 * wJ1, wI1 * wJ2, wI2 * wJ2 });
             result.SetPixel(i, j, col);
         }
     }
     return result;
 }
Example #2
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]));
     }
 }
Example #3
0
 public static Bitmap ToBitmap(Bitmap2 bitmap)
 {
     if (bitmap == null){
         return null;
     }
     Bitmap result = new Bitmap(bitmap.Width, bitmap.Height);
     for (int i = 0; i < bitmap.Width; i++){
         for (int j = 0; j < bitmap.Height; j++){
             result.SetPixel(i, j, Color.FromArgb(bitmap.GetPixel(i, j)));
         }
     }
     return result;
 }
Example #4
0
 public static Bitmap2 ToBitmap2(Bitmap bitmap)
 {
     if (bitmap == null){
         return null;
     }
     Bitmap2 result = new Bitmap2(bitmap.Width, bitmap.Height);
     for (int i = 0; i < bitmap.Width; i++){
         for (int j = 0; j < bitmap.Height; j++){
             result.SetPixel(i, j, bitmap.GetPixel(i, j).ToArgb());
         }
     }
     return result;
 }
Example #5
0
        public Bitmap2 Transpose()
        {
            Bitmap2 result = new Bitmap2(Height, Width);

            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    result.SetPixel(j, i, GetPixel(i, j));
                }
            }
            return(result);
        }
Example #6
0
 public Bitmap2 Darker()
 {
     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.Max(0, Color2.GetR(p) - 20), Math.Max(0, Color2.GetG(p) - 20),
                     Math.Max(0, Color2.GetB(p) - 20)).Value);
         }
     }
     return result;
 }
Example #7
0
        public static Bitmap2 GetImage(string prefix, string file)
        {
            Assembly thisExe = Assembly.GetExecutingAssembly();
            Stream   file1   = thisExe.GetManifestResourceStream(prefix + file);

            if (file1 == null)
            {
                return(null);
            }
            Bitmap2 bm = Image2.ReadImage(file1);

            file1.Close();
            return(bm);
        }
Example #8
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);
        }
Example #9
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);
            }
        }
Example #10
0
        public static Bitmap2 GetImage(char c, int width, int height, Color2 fgColor, Color2 bgColor)
        {
            if (height <= 1 || width <= 1)
            {
                return(null);
            }
            Bitmap2 template = GetImage(c);

            if (template == null)
            {
                return(null);
            }
            int     twidth  = template.Width;
            int     theight = template.Height;
            Bitmap2 result  = new Bitmap2(width, height);

            for (int i = 0; i < width; i++)
            {
                float wI1;
                float wI2;
                int   indI = CalcInd(i, width, twidth, out wI1, out wI2);
                for (int j = 0; j < height; j++)
                {
                    float  wJ1;
                    float  wJ2;
                    int    indJ = CalcInd(j, height, theight, out wJ1, out wJ2);
                    Color2 ij   = IsSet(indI, indJ, template) ? fgColor : bgColor;
                    Color2 ipj  = IsSet(indI + 1, indJ, template) ? fgColor : bgColor;
                    Color2 ijp  = IsSet(indI, indJ + 1, template) ? fgColor : bgColor;
                    Color2 ipjp = IsSet(indI + 1, indJ + 1, template) ? fgColor : bgColor;
                    Color2 col  = Average(new[] { ij, ipj, ijp, ipjp }, new[] { wI1 *wJ1, wI2 *wJ1, wI1 *wJ2, wI2 *wJ2 });
                    result.SetPixel(i, j, col);
                }
            }
            return(result);
        }
Example #11
0
        private static Bitmap2 GetImage(char c)
        {
            switch (c)
            {
            case 'A':
                return(Bitmap2.GetImage("chara.bmp"));

            case 'B':
                return(Bitmap2.GetImage("charb.bmp"));

            case 'C':
                return(Bitmap2.GetImage("charc.bmp"));

            case 'D':
                return(Bitmap2.GetImage("chard.bmp"));

            case 'E':
                return(Bitmap2.GetImage("chare.bmp"));

            case 'F':
                return(Bitmap2.GetImage("charf.bmp"));

            case 'G':
                return(Bitmap2.GetImage("charg.bmp"));

            case 'H':
                return(Bitmap2.GetImage("charh.bmp"));

            case 'I':
                return(Bitmap2.GetImage("chari.bmp"));

            case 'J':
                return(Bitmap2.GetImage("charj.bmp"));

            case 'K':
                return(Bitmap2.GetImage("chark.bmp"));

            case 'L':
                return(Bitmap2.GetImage("charl.bmp"));

            case 'M':
                return(Bitmap2.GetImage("charm.bmp"));

            case 'N':
                return(Bitmap2.GetImage("charn.bmp"));

            case 'O':
                return(Bitmap2.GetImage("charo.bmp"));

            case 'P':
                return(Bitmap2.GetImage("charp.bmp"));

            case 'Q':
                return(Bitmap2.GetImage("charq.bmp"));

            case 'R':
                return(Bitmap2.GetImage("charr.bmp"));

            case 'S':
                return(Bitmap2.GetImage("chars.bmp"));

            case 'T':
                return(Bitmap2.GetImage("chart.bmp"));

            case 'U':
                return(Bitmap2.GetImage("charu.bmp"));

            case 'V':
                return(Bitmap2.GetImage("charv.bmp"));

            case 'W':
                return(Bitmap2.GetImage("charw.bmp"));

            case 'X':
                return(Bitmap2.GetImage("charx.bmp"));

            case 'Y':
                return(Bitmap2.GetImage("chary.bmp"));

            case 'Z':
                return(Bitmap2.GetImage("charz.bmp"));

            case 'a':
                return(Bitmap2.GetImage("char_a.bmp"));

            case 'b':
                return(Bitmap2.GetImage("char_b.bmp"));

            case 'c':
                return(Bitmap2.GetImage("char_c.bmp"));

            case 'd':
                return(Bitmap2.GetImage("char_d.bmp"));

            case 'e':
                return(Bitmap2.GetImage("char_e.bmp"));

            case 'f':
                return(Bitmap2.GetImage("char_f.bmp"));

            case 'g':
                return(Bitmap2.GetImage("char_g.bmp"));

            case 'h':
                return(Bitmap2.GetImage("char_h.bmp"));

            case 'i':
                return(Bitmap2.GetImage("char_i.bmp"));

            case 'j':
                return(Bitmap2.GetImage("char_j.bmp"));

            case 'k':
                return(Bitmap2.GetImage("char_k.bmp"));

            case 'l':
                return(Bitmap2.GetImage("char_l.bmp"));

            case 'm':
                return(Bitmap2.GetImage("char_m.bmp"));

            case 'n':
                return(Bitmap2.GetImage("char_n.bmp"));

            case 'o':
                return(Bitmap2.GetImage("char_o.bmp"));

            case 'p':
                return(Bitmap2.GetImage("char_p.bmp"));

            case 'q':
                return(Bitmap2.GetImage("char_q.bmp"));

            case 'r':
                return(Bitmap2.GetImage("char_r.bmp"));

            case 's':
                return(Bitmap2.GetImage("char_s.bmp"));

            case 't':
                return(Bitmap2.GetImage("char_t.bmp"));

            case 'u':
                return(Bitmap2.GetImage("char_u.bmp"));

            case 'v':
                return(Bitmap2.GetImage("char_v.bmp"));

            case 'w':
                return(Bitmap2.GetImage("char_w.bmp"));

            case 'x':
                return(Bitmap2.GetImage("char_x.bmp"));

            case 'y':
                return(Bitmap2.GetImage("char_y.bmp"));

            case 'z':
                return(Bitmap2.GetImage("char_z.bmp"));
            }
            return(null);
        }
Example #12
0
 public void DrawImage(Bitmap2 image, float x, float y, float width, float height)
 {
     Image img = null;
     try{
         img = Image.GetInstance(GraphUtils.ToBitmap(image), System.Drawing.Imaging.ImageFormat.Tiff);
     } catch (Exception ex){
         Console.Error.WriteLine(ex.Message);
     }
     if (img != null){
         img.ScaleAbsolute(width, height);
         img.SetAbsolutePosition(x, (currentHeight - img.ScaledHeight) - y);
         template.AddImage(img);
     }
 }
 private void PaintBar(IGraphics g, int scrollBarWid, int height)
 {
     if (!HasBar){
         return;
     }
     if (bar != null && CalcBarSize(height) != bar.Height){
         bar = null;
     }
     if (bar == null){
         CreateBar(scrollBarWid, height);
     }
     int h = CalcBarStart(height);
     switch (state){
         case ScrollBarState.HighlightBar:
             g.DrawImageUnscaled(barHighlight, 1, h);
             break;
         case ScrollBarState.PressBar:
             g.DrawImageUnscaled(barPress, 1, h);
             break;
         default:
             g.DrawImageUnscaled(bar, 1, h);
             break;
     }
 }
 private void CreateSecondMark(int scrollBarWid)
 {
     int w = scrollBarWid - 2;
     int h = scrollBarWid - 1;
     Bitmap2 b = new Bitmap2(w, h);
     GraphUtil.FillShadedRectangle(b, w, h);
     Bitmap2 bh = b.Lighter();
     Bitmap2 bp = b.Darker();
     secondMark = b;
     secondMarkHighlight = bh;
     secondMarkPress = bp;
 }
 private void CreateBar(int scrollBarWid, int height)
 {
     int w = scrollBarWid - 2;
     int h = CalcBarSize(height);
     Bitmap2 b = new Bitmap2(w, h);
     GraphUtil.FillShadedRectangle(b, w, h);
     Bitmap2 bh = b.Lighter();
     Bitmap2 bp = b.Darker();
     bar = b;
     barHighlight = bh;
     barPress = bp;
 }
 public override void OnResize(EventArgs e, int width, int height)
 {
     bar = null;
 }
 private void CreateFirstMark(int scrollBarWid)
 {
     int w = scrollBarWid - 1;
     int h = scrollBarWid - 2;
     Bitmap2 b = new Bitmap2(w, h);
     GraphUtil.FillShadedRectangle(b, w, h);
     firstMark = b;
     firstMarkHighlight = b.Lighter();
     firstMarkPress = b.Darker();
 }
Example #18
0
 private static bool IsSet(int i, int j, Bitmap2 b)
 {
     return(Color2.GetR(b.GetPixel(i, j)) == 0);
 }
Example #19
0
 /// <summary>
 /// Draws the specified image using its original physical size at the location specified by a coordinate pair.
 /// </summary>
 /// <param name="image">Image to draw.</param>
 /// <param name="x">The x-coordinate of the upper-left corner of the drawn image.</param>
 /// <param name="y">The y-coordinate of the upper-left corner of the drawn image.</param>
 public void DrawImageUnscaled(Bitmap2 image, float x, float y)
 {
     imageList.Add(new SvgImage{X = x, Y = y, Transform = Transform});
 }
Example #20
0
 public void DrawImageUnscaled(Bitmap2 image, float x, float y)
 {
     // TODO reduce the resolution to fit (?)
     try{
         Image img = Image.GetInstance(GraphUtils.ToBitmap(image),
             System.Drawing.Imaging.ImageFormat.Tiff);
         img.SetAbsolutePosition(x, (currentHeight - img.ScaledHeight) - y);
         template.AddImage(img);
     } catch{}
 }
Example #21
0
 private static bool IsSet(int i, int j, Bitmap2 b)
 {
     return Color2.GetR(b.GetPixel(i, j)) == 0;
 }
Example #22
0
 public Bitmap2 Transpose()
 {
     Bitmap2 result = new Bitmap2(Height, Width);
     for (int i = 0; i < Width; i++){
         for (int j = 0; j < Height; j++){
             result.SetPixel(j, i, GetPixel(i, j));
         }
     }
     return result;
 }
Example #23
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]));
            }
        }
Example #24
0
 /// <summary>
 /// Draws the specified Image at the specified location and with the specified size.
 /// </summary>
 /// <param name="image">Image to draw.</param>
 /// <param name="x">The x-coordinate of the upper-left corner of the drawn image.</param>
 /// <param name="y">The y-coordinate of the upper-left corner of the drawn image.</param>
 /// <param name="width">Width of the drawn image.</param>
 /// <param name="height">Height of the drawn image.</param>
 public void DrawImage(Bitmap2 image, float x, float y, float width, float height)
 {
     imageList.Add(new SvgImage{X = x, Y = y, Transform = Transform});
 }