Click here to Skip to main content
Click here to Skip to main content

A Powerful Photo Editing App and Effects.

By , 22 Oct 2012
 

Please note

This article is an entry in our AppInnovation Contest. Articles in this sub-section are not required to be full articles so care should be taken when voting.

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.

License

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

About the Author

pratik mohapatra
India India
Member
Hello people i am a developer aged 14 years and i have build 3 applications. Moreover i am looking forward to crating more apps. I have developed a lot of apps on Intel app up. Look forward to create more applications for windows store. Thanks code project.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionExcellentmemberRocky9925 Oct '12 - 7:00 
This app is a really good app as it takes use of the compass sensor of the new ultrabook and it also takes use of the new windows 8 interface. You are a really good young developer.
GeneralMy vote of 5memberVijay Vb22 Oct '12 - 18:23 
Nice Pratik! But doesn't gimp run rounds on your app or are apps just small and supposed to be small. BTW make You're app free if there are other apps doing the same thing.
 
Vijay.
QuestionappmemberMember 953039719 Oct '12 - 21:02 
gud app
GeneralMy vote of 5memberchandychandana119 Oct '12 - 19:10 
d app is gud
QuestionHow does this make use of the features of an Ultrabook?adminChris Maunder19 Oct '12 - 8:48 
More details, please.
cheers,
Chris Maunder
 
The Code Project | Co-founder
Microsoft C++ MVP

AnswerRe: How does this make use of the features of an Ultrabook? [modified]memberpratik mohapatra19 Oct '12 - 17:52 
Sir it takes use of the multiple cores present in the system to optimize the app.

modified 20 Oct '12 - 0:31.

GeneralRe: How does this make use of the features of an Ultrabook?memberRanjan.D19 Oct '12 - 21:34 
This contest is about how you are showcasing the Ultrabook sensors in your App. using multiple cores may be a part of your App.
 
Consider redesigning and explain how you are going to use ultra book sensors
 
Thanks,
Ranjan.D

GeneralRe: How does this make use of the features of an Ultrabook?memberpratik mohapatra19 Oct '12 - 21:51 
Thank you sir but sir i have already worked a lot on this app and using multiple cores in one feature and sir and in the next update i will make it touch and enable gyroscope.
 
Thank You.
Pratik

GeneralRe: How does this make use of the features of an Ultrabook?memberRanjan.D19 Oct '12 - 22:01 
You next update should not cross beyond Oct 24 that is one reason I said to revise and update the article. Else you would be missing a nice Ultrabook.
 
As a contest we all wish to submit it to Intel AppUp and per contest we need to make use of at least few sensors in our App.
 
Thanks,
Ranjan.D

GeneralRe: How does this make use of the features of an Ultrabook?memberpratik mohapatra19 Oct '12 - 22:03 
Sir one question how do i enable sensors in an c# app. Can you please help me.
GeneralRe: How does this make use of the features of an Ultrabook?memberRanjan.D19 Oct '12 - 22:09 
You need not enable sensor in your code. You just have to get the default instance. Handle null conditions because if the user runs the same App in non ultra book then the sensors won't be available.
 
There are few samples you can find in net so will get a good idea on the usage of sensors
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465294.aspx[^]
 
Also you can refer my article
 
Travel Manager[^]
 
Thanks,
Ranjan.D

GeneralRe: How does this make use of the features of an Ultrabook?memberpratik mohapatra19 Oct '12 - 22:13 
So sir i can use the same code. So where should i insert the sensors code.
 

Thank You.
GeneralRe: How does this make use of the features of an Ultrabook?memberRanjan.D19 Oct '12 - 22:18 
There are sample sensor codes available in MSDN. Please feel free to analyze and reuse the code.
 
I just gave you my article link so that you will get a fare idea on the usage of sensor so that you can review your App and get some idea.
 
Thanks,
Ranjan.D

GeneralRe: How does this make use of the features of an Ultrabook?memberpratik mohapatra19 Oct '12 - 22:20 
Sir i cant use C# 2010 express for this?
GeneralRe: How does this make use of the features of an Ultrabook?memberRanjan.D19 Oct '12 - 22:24 
The other thing if you are not aware. The sensors comes in 4.5 Win RT. So you will have develop you application in Win 8
 
Also if you want to include the Win RT library in your Desktop application then please follow the below mentioned article
 
http://www.hanselman.com/blog/HowToCallWinRTAPIsInWindows8FromCDesktopApplicationsWinRTDiagram.aspx[^]
 
Thanks,
Ranjan.D

GeneralRe: How does this make use of the features of an Ultrabook?memberpratik mohapatra19 Oct '12 - 22:26 
So sir this code is in c# 2010 can i use the same code in windows 8 visual studio 2012 express.
GeneralRe: How does this make use of the features of an Ultrabook?memberRanjan.D19 Oct '12 - 22:29 
Sure you can migrate it easily to VS 2012. It happens automatically when you open up your solution. Also refer the previous post link that I have mentioned on the usage of Win RT library in your desktop Apps. If you include those libraries only you can access the sensors
 
Thanks,
Ranjan.D

GeneralRe: How does this make use of the features of an Ultrabook?memberpratik mohapatra19 Oct '12 - 22:31 
So sir last question where do i get the libraries will it be present in s 2012 express already?
GeneralRe: How does this make use of the features of an Ultrabook?memberRanjan.D19 Oct '12 - 22:36 
As I'm aware , with VS 2012 Express it is not possible to develop desktop application. You may have to download VS 2012 Professional Trial and use the same.
 
Once you have VS 2012 Pro you will have access to all the Win RT libraries and can develop desktop App. Please refer previous article link on how to use sensors in your Application.
 
Thanks,
Ranjan.D

AnswerRe: How does this make use of the features of an Ultrabook?memberpratik mohapatra26 Oct '12 - 2:55 
Sit it takes features of the compass sensors present in the ultrabook!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 22 Oct 2012
Article Copyright 2012 by pratik mohapatra
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid