コード例 #1
0
        private void menuGrayscale_Click(object sender, EventArgs e)
        {
            if (picBoxMain.Image != null)
            {
                Grayscale dlgGrayscale = new Grayscale();
                DialogResult dlgResult;
                dlgResult = dlgGrayscale.ShowDialog();
                listLoadedImg[curImgIndex].CreatePreviousVer();

                // tmp created for readability, will eventually be applied to picBoxMain
                Bitmap tmp;

                // The 'Luminosity' button is set to "OK".
                if (dlgResult == DialogResult.OK)
                {
                    tmp = ApplyGrayscale(listLoadedImg[curImgIndex].GetBitmap("c"), "luminosity");
                    listLoadedImg[curImgIndex].UpdateBitmap("c", tmp);
                    picBoxMain.Image = tmp;
                }
                // The 'Average' button is set to "Yes".
                else if (dlgResult == DialogResult.Yes)
                {
                    tmp = ApplyGrayscale(listLoadedImg[curImgIndex].GetBitmap("c"), "average");
                    listLoadedImg[curImgIndex].UpdateBitmap("c", tmp);
                    picBoxMain.Image = tmp;
                }
                else
                {
                    MessageBox.Show("An error has occured during the grayscale operation.");
                    Environment.Exit(22);
                }
            }
        }
コード例 #2
0
ファイル: PicViewer.cs プロジェクト: Chrisjw42/PictureViewer
        private void menuGrayscale_Click_1(object sender, EventArgs e)
        {
            if (picBoxMain.Image != null)
            {
                Grayscale dlgGrayscale = new Grayscale();
                DialogResult dlgResult;
                dlgResult = dlgGrayscale.ShowDialog();

                // tmp created for readability, will eventually be applied to picBoxMain
                Bitmap tmp = null;

                // The 'Luminosity' button is set to "OK".
                if (dlgResult == DialogResult.OK)
                {
                    // tmp = ApplyGrayscale(listLoadedImg[curImgIndex].GetBitmap("c"), "luminosity");
                    tmp = adjustImg.GetGrayscale(listLoadedImg[curImgIndex].GetBitmap("c"), "luminosity");
                }
                // The 'Average' button is set to "Yes".
                else if (dlgResult == DialogResult.Yes)
                {
                    // tmp = ApplyGrayscale(listLoadedImg[curImgIndex].GetBitmap("c"), "average");
                    tmp = adjustImg.GetGrayscale(listLoadedImg[curImgIndex].GetBitmap("c"), "average");
                }
                else
                {
                    MessageBox.Show("An error has occured during the grayscale operation.");
                    Environment.Exit(22);
                }
                // If we reached here, a certain kind of grayscaling has been applied
                listLoadedImg[curImgIndex].UpdateBitmap(tmp);
                UpdatePicbox(listLoadedImg[curImgIndex]);
            }
        }
コード例 #3
0
        private void menuBatchGrayscale_Click(object sender, EventArgs e)
        {
            using (Grayscale dlgGrayscale = new Grayscale())
            {
                if (dlgGrayscale.ShowDialog() != DialogResult.Cancel)
                {
                    string algorithm = null;

                    // "OK" is the result assigned to the luminosity button
                    if (dlgGrayscale.DialogResult == DialogResult.OK)
                    {
                        algorithm = "luminosity";
                    }
                    else if (dlgGrayscale.DialogResult == DialogResult.Yes)
                    {
                        algorithm = "average";
                    }
                    else
                    {
                        // This should never happen
                        dlgGrayscale.Close();
                    }

                    // Make changes initially before deciding on whether to save, etc.
                    foreach (LoadedImage img in listLoadedImg)
                    {
                        listLoadedImg[curImgIndex].CreatePreviousVer();
                        img.UpdateBitmap("c", ApplyGrayscale(img.GetBitmap("c"), algorithm));
                    }
                    UpdatePicbox(listLoadedImg[curImgIndex]);
                    BatchFileProcess();
                }
            }
        }