Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i changed my question.

ignore the tint and noise...the contrast seems working....
the black and white is working but not based on trackbar1.value.

for the contrast, i use contrast = 0.04f * trackbar1.value.
i don't know how to put the trackbar1.value on my black and white.

C#
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)
            {   
            }
        }
    }
}


VB
tools I'm using:
*4 RadioButton(contrast, black&white, Tint, Noise).
*2 buttons (Load Picture and Transform(the Transform button will start an image manipulation based on the current settings.)
*Trackbar - will control the extent, and its interpretation is effect dependent.
Posted
Updated 15-Oct-11 5:54am
v4
Comments
Sergey Alexandrovich Kryukov 15-Oct-11 2:25am    
Not a question. Do you understand we do not develop software to any requirements? As to your own code, you do not explain anything about it and do not ask of any particular problem. This post is inappropriate, sorry. You can make is acceptable using "Improve question". Explain where you face some particular problems.
--SA
OriginalGriff 15-Oct-11 10:06am    
It's still not a question - don't just bump your question, or it will be deleted...

1 solution

OK, one single line shows you have no idea what are you writing and why:

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


Without looking at the context, it's clear that you format integer value into human-readable string representing it, and then parse it into integer again. Amazing! Would was the idea behind that?

The methods RB_contrast_CheckedChanged and RB_blackwhite_CheckedChanged do exact same thing and two next method do almost the same, not clear why. You just repeat the code. Do you understand that you should never repeat the same code anywhere? Do you understand the danger of it? I have no idea how to help you, because it looks like you do some random things without understanding why. It goes nowhere. Maybe you need to learn to apply brain instead of trying this and that.

By the way, the question is still not clear. It looks like you writing questions using the same "method" as in writing code.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900