Link to home
Start Free TrialLog in
Avatar of anas-kal2
anas-kal2

asked on

processing image with c# form

hi experts
iam working on c#  project-<windows application> - (operations on image such zoom,invert..).

and i want codes for:
 zoom image in ,
 save image as ,
 undo for 3 times,
 smooth matrix,


 //note: i had  written this code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication5
{
    public partial class Form1 : Form
    {
        Bitmap borg;
        Bitmap binv;
        Bitmap bgrey;
        Bitmap bbri;






        #region onpaint
        protected override void  OnPaint(PaintEventArgs e)
        {
           if (borg!=null){
               e.Graphics.DrawImage(borg, ClientRectangle);


            }
            if (binv != null)
            {
                e.Graphics.DrawImage(binv, ClientRectangle);


            }
            if (bgrey != null) {
                e.Graphics.DrawImage(bgrey,ClientRectangle);
            }

            if (bbri != null) {
                e.Graphics.DrawImage(bbri, ClientRectangle);
           
            }
        }
#endregion onpaint

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK) {
                borg = new Bitmap(ofd.FileName);
               
                this.AutoScrollMinSize = borg.Size;
                Refresh();
           
           
            }

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void limToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //invert color
            binv = new Bitmap(borg.Width, borg.Height);
            for(int x=0;x<borg.Width;x++)
                for (int y = 0; y < borg.Height; y++) {
                    Color c = borg.GetPixel(x, y);

                    int r = c.R;
                    int g = c.G;
                    int b = c.B;


                    r = 255 - r;
                    g = 255 - g;
                    r = 255 - b;


             if (r > 255) r = 255; if (r < 0) r = 0;
             if (g > 255) g = 255; if (g < 0) g = 0;
             if (b > 255) b = 255; if (b < 0) b = 0;

                       
                Color cnew=Color.FromArgb(r,g,b) ;
                binv.SetPixel(x, y, cnew);




               
               
                }
                 Refresh();
           }



        private void invertToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //grey color


            bgrey = new Bitmap(borg.Width, borg.Height);
            for (int x = 0; x < borg.Width; x++)
                for (int y = 0; y < borg.Height; y++)
                {
                    Color c = borg.GetPixel(x, y);

                    int l = (int)(0.3 * c.R + 0.49 * c.G + 0.11 * c.G);
                    Color cnew = Color.FromArgb(l, l, l);
                    bgrey.SetPixel(x, y, cnew);



                }
            Refresh();
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
                        Refresh();


        }

        private void trackBar1_Scroll_1(object sender, EventArgs e)
        {
            bbri = new Bitmap(borg.Width, borg.Height);
            for (int x = 0; x < borg.Width; x++)
                for (int y = 0; y < borg.Height; y++)
                {
                    Color c = borg.GetPixel(x, y);

                    int r = c.R + brtrack.Value;
                    int g = c.G + brtrack.Value;
                    int b = c.B + brtrack.Value;



                    if (r > 255) r = 255; if (r < 0) r = 0;
                    if (g > 255) g = 255; if (g < 0) g = 0;
                    if (b > 255) b = 255; if (b < 0) b = 0;


                    Color cnew = Color.FromArgb(r, g, b);
                    bbri.SetPixel(x, y, cnew);


                }
            Refresh();

        }
    }
}

  best regards
anas-kal2

ASKER CERTIFIED SOLUTION
Avatar of rameedev
rameedev
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial