示例#1
0
    internal static Bitmap[] generateColourMaps(Bitmap pic, List <Color> cols)
    {
        Bitmap[]      CMaps   = new Bitmap[cols.Count];
        FormLoadingcs frmldgn = new FormLoadingcs();
        int           count   = -1;

        for (int i = 0; i < CMaps.Length; i++)
        {
            if (i < compcol.Count - 1)
            {
                frmldgn.Text = "Generating - " + coloursInv[compcol[i]] + " (" + (i + 1) + "/" + compcol.Count + ")";
            }
            else
            {
                frmldgn.Text = "Generating - White" + " (" + (i + 1) + "/" + compcol.Count + ")";
            }

            frmldgn.Show();

            Bitmap colpic = new Bitmap(pic.Width, pic.Height, PixelFormat.Format24bppRgb);

            for (int y = 0; y < pic.Height; y++)
            {
                count++;
                for (int x = 0; x < pic.Width; x++)
                {
                    Color col1 = pic.GetPixel(x, y);
                    if (col1 == compcol[i])
                    {
                        colpic.SetPixel(x, y, Color.FromArgb(0, 0, 0));
                    }
                    else
                    {
                        colpic.SetPixel(x, y, Color.FromArgb(255, 255, 255));
                    }
                }
                frmldgn.setProgress((int)(((float)count / (float)pic.Height * 100f) / compcol.Count));
            }
            CMaps[i] = colpic;
        }
        frmldgn.Close();
        return(CMaps);
    }
示例#2
0
    internal static Bitmap[,] generatePatternMaps(Bitmap[] ColMaps)
    {
        //create a 2 dimensional array
        Bitmap[,] Patterns = new Bitmap[ColMaps.Length - 1, 2];
        //take colour image
        FormLoadingcs frmldgn = new FormLoadingcs();

        patternProgressCount = -1;
        frmldgn.Show();
        int counter = 0;

        for (int i = 0; i < ColMaps.Length - 1; i++)
        {
            counter++;
            Bitmap bmp = ColMaps[i];
            //create 2 bitmaps, one for the outline and the other for the filling
            Bitmap Outline = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format24bppRgb);
            Bitmap Filling = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format24bppRgb);

            if (i < compcol.Count - 1)
            {
                frmldgn.Text = "Generating Outline - " + coloursInv[compcol[i]] + " (" + (counter) + "/" + ((compcol.Count - 1) * 2) + ")";
            }

            //call an outlining method on the first bitmap, specify colour
            Outline = findOutline(Color.FromArgb(255, 0, 0), bmp, frmldgn);
            //call a filling method on the second bitmap, specify colour
            counter++;
            if (i < compcol.Count - 1)
            {
                frmldgn.Text = "Generating Filling - " + coloursInv[compcol[i]] + " (" + (counter) + "/" + ((compcol.Count - 1) * 2) + ")";
            }

            Filling = findFilling(Color.FromArgb(0, 255, 0), Outline, bmp, frmldgn);
            //add the 2 bitmaps to the Array
            Patterns[i, 0] = Outline;
            Patterns[i, 1] = Filling;
        }
        frmldgn.Close();
        return(Patterns);
    }
示例#3
0
    internal static Bitmap dither(Bitmap src1, int width, int height, List <Color> Compcol)
    {
        Bitmap        diffBM = new Bitmap(width, height, PixelFormat.Format24bppRgb);
        FormLoadingcs frmld  = new FormLoadingcs(false, "Dithering");

        frmld.Show();
        int progress = 0;

        if (Compcol.Count > 2)
        {
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Color col1   = src1.GetPixel(x, y);
                    Color newcol = Color.FromArgb(255, 255, 255);
                    int   coldif = 256;

                    foreach (Color col in Compcol)
                    {
                        int r = 0, g = 0, b = 0;
                        r = Math.Abs(col1.R - col.R);
                        g = Math.Abs(col1.G - col.G);
                        b = Math.Abs(col1.B - col.B);

                        int dif = ((r + g + b) / 3);
                        if (dif < coldif)
                        {
                            coldif = dif;
                            newcol = col;
                        }
                    }
                    diffBM.SetPixel(x, y, newcol);
                }
                progress = (int)((float)y / (float)height * 100);
                frmld.setProgress(progress);
            }
        }
        else
        {
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Color col1   = src1.GetPixel(x, y);
                    Color newcol = Color.FromArgb(255, 255, 255);
                    Color col    = compcol[0];

                    int Avg = (col1.R + col1.G + col1.B) / 3;
                    if (Avg > 127)
                    {
                        newcol = Color.FromArgb(255, 255, 255);
                    }
                    else
                    {
                        newcol = col;
                    }

                    diffBM.SetPixel(x, y, newcol);
                }
                progress = (int)((float)y / (float)height * 100);
                frmld.setProgress(progress);
            }
        }
        frmld.Close();
        return(diffBM);
    }