Esempio n. 1
0
        private void floydSteinbergToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int[,] palletteColor = new int[, ] {
                { 0, 0, 0 }, { 255, 0, 0, }, { 0, 255, 0 }, { 0, 0, 255 },
                { 255, 255, 0 }, { 0, 255, 255 }, { 255, 0, 255 }, { 255, 255, 255 }
            };

            Bitmap b = new Bitmap((Bitmap)this.pbInput.Image);
            int    merah, hijau, biru;
            int    errorR, errorG, errorB;

            int[] warnaTerdekat;
            int[] errorColor = new int[3];
            progressBar1.Visible = true;
            for (int i = 1; i <= b.Width - 2; i++)
            {
                for (int j = 0; j <= b.Height - 2; j++)
                {
                    merah         = b.GetPixel(i, j).R;
                    hijau         = b.GetPixel(i, j).G;
                    biru          = b.GetPixel(i, j).B;
                    warnaTerdekat = OlahCitra.warnaTerdekat(merah, hijau, biru);
                    errorR        = merah - warnaTerdekat[0];
                    errorG        = hijau - warnaTerdekat[1];
                    errorB        = biru - warnaTerdekat[2];
                    errorColor[0] = OlahCitra.truncate(errorR);
                    errorColor[1] = OlahCitra.truncate(errorG);
                    errorColor[2] = OlahCitra.truncate(errorB);

                    //hitung pixel koordinat i+1, j
                    merah = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i + 1, j).R + (7.0 / 16.0) * errorColor[0]));
                    hijau = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i + 1, j).G + (7.0 / 16.0) * errorColor[1]));
                    biru  = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i + 1, j).B + (7.0 / 16.0) * errorColor[2]));
                    b.SetPixel(i + 1, j, Color.FromArgb(merah, hijau, biru));

                    //hitung pixel koordinat i-1, j+1
                    merah = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i - 1, j + 1).R + (3.0 / 16.0) * errorColor[0]));
                    hijau = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i - 1, j + 1).G + (3.0 / 16.0) * errorColor[1]));
                    biru  = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i - 1, j + 1).B + (3.0 / 16.0) * errorColor[2]));
                    b.SetPixel(i - 1, j + 1, Color.FromArgb(merah, hijau, biru));

                    //hitung pixel koordinat i, j+1
                    merah = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i, j + 1).R + (5.0 / 16.0) * errorColor[0]));
                    hijau = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i, j + 1).G + (5.0 / 16.0) * errorColor[1]));
                    biru  = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i, j + 1).B + (5.0 / 16.0) * errorColor[2]));
                    b.SetPixel(i, j + 1, Color.FromArgb(merah, hijau, biru));

                    //hitung pixel koordinat i+1, j+1
                    merah = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i + 1, j + 1).R + (1.0 / 16.0) * errorColor[0]));
                    hijau = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i + 1, j + 1).G + (1.0 / 16.0) * errorColor[1]));
                    biru  = OlahCitra.truncate(Convert.ToInt32(b.GetPixel(i + 1, j + 1).B + (1.0 / 16.0) * errorColor[2]));
                    b.SetPixel(i + 1, j + 1, Color.FromArgb(merah, hijau, biru));
                }
                progressBar1.Value = Convert.ToInt16(100 * (i + 1) / b.Width);
            }
            pbOutput.Image       = b;
            progressBar1.Visible = false;
        }
Esempio n. 2
0
        private void nearest8ColorsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int [] baru;
            Bitmap b = new Bitmap((Bitmap)this.pbInput.Image);

            this.pbOutput.Image  = b;
            progressBar1.Visible = true;
            for (int i = 0; i < b.Width; i++)
            {
                for (int j = 0; j < b.Height; j++)
                {
                    Color c1 = b.GetPixel(i, j);
                    baru = OlahCitra.warnaTerdekat(c1.R, c1.G, c1.B);
                    b.SetPixel(i, j, Color.FromArgb(baru[0], baru[1], baru[2]));
                }
                progressBar1.Value = Convert.ToInt16(100 * (i + 1) / b.Width);
            }
            progressBar1.Visible = false;
            this.pbOutput.Image  = b;
        }