返回首页

我改变了我的问题。

忽略的色彩和噪音......对比似乎工作......
黑色和白色的工作,但,不trackbar1.value。

相比之下,我使用对比= 0.04f * trackbar1.value的。
我不知道如何把我的黑色和白色的trackbar1.value。

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Drawing.Imaging;

 

namespace Lab1___J

{

    public partial class Form1 : Form

    {

        Image file;

        Bitmap bm_image;        

        int i_change;

        float contrast = 0;

        public Form1()

        {

            InitializeComponent();            

        }

 

        private void RB_contrast_CheckedChanged(object sender, EventArgs e)

        {

            LBL_color1.Text = "Less";

            LBL_color2.Text = "More";

            trackBar1.SetRange(0, 100);

            trackBar1.TickFrequency = 5;            

        }

 

        private void RB_blackwhite_CheckedChanged(object sender, EventArgs e)

        {

            LBL_color1.Text = "Less";

            LBL_color2.Text = "More";

            trackBar1.SetRange(0, 100);

            trackBar1.TickFrequency = 5;            

        }

 

        private void RB_tint_CheckedChanged(object sender, EventArgs e)

        {

            trackBar1.SetRange(0, 100);

            trackBar1.TickFrequency = 5;

            LBL_color1.Text = "Red";

            LBL_color2.Text = "Green";            

        }

 

        private void RB_noise_CheckedChanged(object sender, EventArgs e)

        {

            LBL_color1.Text = "Less";

            LBL_color2.Text = "More";

            trackBar1.SetRange(0, 100);

            trackBar1.TickFrequency = 5;            

        }

 

        private void BTN_loadpic_Click(object sender, EventArgs e)

        {

 

            Stream myStream = null;

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

 

            openFileDialog1.InitialDirectory = "c:\\";

            openFileDialog1.Filter = "Bitmap Files (*.bmp;*.dib)|*.*|JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.* |PNG (*.png)|*.*|GIF (*.gif)|*.*|All files (*.*)|*.*";

            

            if (openFileDialog1.ShowDialog() == DialogResult.OK)

            {

                try

                {

                    if ((myStream = openFileDialog1.OpenFile()) != null)

                    {

                        using (myStream)

                        {

                            file = Image.FromFile(openFileDialog1.FileName);

                            bm_image = new Bitmap(openFileDialog1.FileName);

                            pictureBox1.Image = file;                            

                        }

                    }

                }

                catch (Exception)

                {

                    MessageBox.Show("Error: Could not read file.", "PicBender", 

                        MessageBoxButtons.OK, MessageBoxIcon.Error);

                }

            }

        }

 

        private void trackBar1_Scroll(object sender, EventArgs e)

        {

            lbl_Tracknum.Text = trackBar1.Value.ToString();

            i_change = int.Parse(trackBar1.Value.ToString());

        }

 

        private void BTN_transform_Click(object sender, EventArgs e)

        {

            bm_image = new Bitmap(pictureBox1.Image);

            if (RB_contrast.Checked)

            {

                contrast = 0.04f * trackBar1.Value;

 

                Bitmap bm = new Bitmap(bm_image.Width, bm_image.Height);

 

                Graphics g = Graphics.FromImage(bm);

 

                ImageAttributes ia = new ImageAttributes();

 

                ColorMatrix cm = new ColorMatrix(new float[][]{

                new float[]{contrast, 0f, 0f, 0f, 0f,},

                new float[]{0f,contrast, 0f, 0f, 0f,},

                new float[]{0f, 0f,contrast, 0f, 0f,},

                new float[]{0f, 0f, 0f, 1f,0f},

                new float[]{0.001f,0.001f,0.001f,0f,1f}});

 

                ia.SetColorMatrix(cm);

 

                g.DrawImage(bm_image, new Rectangle(0, 0, bm_image.Width, bm_image.Height), 0, 0, bm_image.Width, bm_image.Height, GraphicsUnit.Pixel, ia);

                g.Dispose();

                ia.Dispose();

                pictureBox1.Image = bm;

            }

            if (RB_blackwhite.Checked)

            {

                for (int x = 0; x < bm_image.Width; x++)

                {

                    

                    for (int y = 0; y < bm_image.Height; y++)

                    {

                        //get the pixel from the original image

                        Color originalColor = bm_image.GetPixel(x, y);

                        //create the grayscale version of the pixel

                        int newg = (int)((originalColor.A * .3) + (originalColor.G * .59) 

                            + (originalColor.B * .11));

 

                        Color newColor = Color.FromArgb(newg, newg, newg);

                        

                        bm_image.SetPixel(x, y, newColor);

                    }

                }

                pictureBox1.Image = bm_image;

            }

            if (RB_tint.Checked)

            {

            }

            if (RB_noise.Checked)

            {   

            }

        }

    }

}

{C}

回答

评论会员:S 时间:2