Click here to Skip to main content

A Powerful Photo Editing App and Effects.

Introduction

This application helps users to improve their photos and edit them with ease as it is a very light weight application. Also users can save their photos in various formats and also it has very cool effects to play around with. It also has a compass sensor which enables the users to use it in the new ultrabooks and take the use of it. Now this app also supports compass sensors in the ultrabook so you can take you of them.

Background

The main idea is that photo editing has become such a important tool nowadays as users want to edit their photos in the best possible way they can.

Using the Code

This code is written in C# and can be used in C#

The new code is there in the downloads section.

It can be written under Windows Form Application. 

//  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.Drawing.Imaging;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Image img;
        Bitmap newbitmap;
        int bluramount = 1;
        
        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult dr = openFileDialog1.ShowDialog();
            if (dr == DialogResult.OK)
            {
                img = Image.FromFile(openFileDialog1.FileName);
                newbitmap = new Bitmap(openFileDialog1.FileName);
                pictureBox1.Image = img;
                
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dr = saveFileDialog1.ShowDialog();
            if (dr == DialogResult.OK)
            {

                if (img != null)
                {
                    if (saveFileDialog1.FileName.Substring(saveFileDialog1.FileName.Length - 3).ToLower() == "bmp")
                    {
                        img.Save(saveFileDialog1.FileName, ImageFormat.Bmp);
                    }
                    if (saveFileDialog1.FileName.Substring(saveFileDialog1.FileName.Length - 3).ToLower() == "jpg")
                    {
                        img.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);
                    }
                    if (saveFileDialog1.FileName.Substring(saveFileDialog1.FileName.Length - 3).ToLower() == "gif")
                    {
                        img.Save(saveFileDialog1.FileName, ImageFormat.Gif);
                    }

                    if (saveFileDialog1.FileName.Substring(saveFileDialog1.FileName.Length - 3).ToLower() == "png")
                    {
                        img.Save(saveFileDialog1.FileName, ImageFormat.Png);
                    }
                    else
                    {
                        MessageBox.Show("You have to select a picture");
                    }

                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            for (int x = 0; x < newbitmap.Width; x++)
            {
                for (int y = 0; y < newbitmap.Height; y++)
                {
                    Color orginalcolor = newbitmap.GetPixel(x, y);
                    int gyayscale = (int)((orginalcolor.R * .3) + (orginalcolor.G * .59) + (orginalcolor.B * .11));
                    Color newColor = Color.FromArgb(gyayscale, gyayscale, gyayscale);
                    newbitmap.SetPixel(x, y, newColor);
                    pictureBox1.Image = newbitmap;

                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            for (int x =bluramount; x <= newbitmap.Width-bluramount; x++)
            {
                for (int y = bluramount; y <= newbitmap.Height-bluramount; y++)
                {
                    try
                    {
                        Color prevX = newbitmap.GetPixel(x - bluramount, y);
                        Color nextX = newbitmap.GetPixel(x + bluramount, y);
                        Color prevY = newbitmap.GetPixel(x , y-bluramount);
                        Color nextY = newbitmap.GetPixel(x , y+bluramount);

                        int avgR = (int)((prevX.R + nextX.R + prevY.R + nextY.R)/4);
                        int avgG = (int)((prevX.G + nextX.G + prevY.R + nextY.G)/4);
                        int avgB = (int)((prevX.B + nextX.B + prevY.R + nextY.B)/4);

                        newbitmap.SetPixel(x,y,Color.FromArgb(avgR,avgG,avgB));
                        

                    }
                    catch (Exception) { }
                }
            }
            pictureBox1.Image = newbitmap;
        }

        private void progressBar1_Click(object sender, EventArgs e)
        {
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

      
        private void Updateblur(object sender, EventArgs e)
        {
            bluramount = int.Parse(trackBar1.Value.ToString());
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            label3.Text = trackBar2.Value.ToString();
            pictureBox1.Image = AdjustBrightness(newbitmap, trackBar2.Value);
        }

        public static Bitmap AdjustBrightness(Bitmap Image, int Value)
        {
            Bitmap TempBitmap = Image;
            float FinalValue = (float)Value / 255.0f;
            Bitmap NewBitmap = new Bitmap(TempBitmap.Width, TempBitmap.Height);
            Graphics NewGraphics = Graphics.FromImage(NewBitmap);
            float[][] FloatColorMatrix ={
                      new float[] {1, 0, 0, 0, 0},
                      new float[] {0, 1, 0, 0, 0},
                      new float[] {0, 0, 1, 0, 0},
                      new float[] {0, 0, 0, 1, 0},
                      new float[] {FinalValue, FinalValue, FinalValue, 1, 1}
                 };

            ColorMatrix NewColorMatrix = new ColorMatrix(FloatColorMatrix);
            ImageAttributes Attributes = new ImageAttributes();
            Attributes.SetColorMatrix(NewColorMatrix);
            NewGraphics.DrawImage(TempBitmap, new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, GraphicsUnit.Pixel, Attributes);
            Attributes.Dispose();
            NewGraphics.Dispose();
            return NewBitmap;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            for (int x = 0; x < newbitmap.Width; x++)
            {
                for (int y = 0; y < newbitmap.Height; y++)
                {
                    Color pixel = newbitmap.GetPixel(x, y);
                    int red = pixel.R;
                    int green = pixel.G;
                    int blue = pixel.B;
                    newbitmap.SetPixel(x,y,Color.FromArgb(255-red,255-green,255-blue));
                }
            } pictureBox1.Image = newbitmap;
        }

        private void button6_Click(object sender, EventArgs e)

        {
            int lastCol=0;
            Bitmap nB = new Bitmap(newbitmap.Width, newbitmap.Height);

            for (int x = 1; x <= newbitmap.Width - 1; x++)
            {
                for (int y = 1; y <= newbitmap.Height - 1; y++)
                {
                    nB.SetPixel(x, y, Color.DarkGray);
                }
            }

            for (int x = 1; x <= newbitmap.Width - 1; x++)
            {
                for (int y = 1; y <= newbitmap.Height - 1; y++)
                {
                    try
                    {
                        Color pixel = newbitmap.GetPixel(x, y);

                        int colVal = (pixel.R + pixel.G + pixel.B);

                        if (lastCol == 0) lastCol = (pixel.R + pixel.G + pixel.B);

                        int diff;

                        if (colVal > lastCol) { diff = colVal - lastCol; } else { diff = lastCol - colVal; }

                        if (diff > 100)
                        {
                            nB.SetPixel(x, y, Color.Gray);
                            lastCol = colVal;
                        }


                    }
                    catch (Exception) { }
                }
            }

            for (int y = 1; y <= newbitmap.Height - 1; y++)
            {

                for (int x = 1; x <= newbitmap.Width - 1; x++)
                {
                    try
                    {
                        Color pixel = newbitmap.GetPixel(x, y);

                        int colVal = (pixel.R + pixel.G + pixel.B);

                        if (lastCol == 0) lastCol = (pixel.R + pixel.G + pixel.B);

                        int diff;

                        if (colVal > lastCol) { diff = colVal - lastCol; } else { diff = lastCol - colVal; }

                        if (diff > 100)
                        {
                            nB.SetPixel(x, y, Color.Gray);
                            lastCol = colVal;
                        }

                    }
                    catch (Exception) { }
                }

            }

            pictureBox1.Image = nB;
        }


    }
}

Points of Interest

This app will help you edit your photos very easily and it is a very light weight application. Moreover I learned how to create apps and the code of the app was not easy but patience was the key to success.

The most annoying thing in C# which I don't like is putting ";" after every line or the compiler shows a error. Moreover C# is actually pretty simple in the way which is drag and drop. Also it has a compass sensor.

 

 

 

History

In this article I have updated about the compass sensor in my app. And this compass sensor makes the app ultrabook compatible.


Web03 | 2.8.160204.4 | Advertise | Privacy
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service