Click here to Skip to main content
Licence CPOL
First Posted 7 Nov 2006
Views 32,723
Downloads 1,740
Bookmarked 18 times

Very Simple Paint

By | 7 Nov 2006 | Article
Painting with different colors into the images
Sample Image - sources_very_simple_paint.jpg

Introduction

I was working on a project and I needed to make some changes to images such as delete and remove information and mark some features using a different type, width and colors to the pencil.

Using the Code

The core of this small code is the usage of the Graphics object. Usually, you can use it to paint something to the picture to provide some information to the client but really you don't paint within a Bitmap structure. In this case, you obtain your goal using the Graphics of visual component like:

Graphics graphics = pictureBox.CreateGraphics();

But this way requires that you do all your paint operations on the paint event of pictureBox because all modifications belong to the visual control and not to the bitmap structure. Besides one application like this should generate several paint events and you must redraw unnecessary things in each paint operation. Due to the reasons previously commented, I did my paint operations using the graphics of bitmap directly like:

Graphics graphics = Graphics.FromImage(bitmap);

You must be careful because you are applying transformations to the original bitmap. First make a copy if you want to save the original image. To obtain the changed image, you must only read the variable bitmap used to create the graphics. In the application, you can see the usage of the Cursor object to visually establish the difference of pencils.

/// <summary>
/// Set the image to pointer
/// </summary>
private void SetMouseCursor()
{
    string name = picBoxClicked.Name;
    switch (name)
    {
        case "picBoxCircleBig":
            Cursor = new Cursor("CursorCircleBig.cur");
            break;
        case "picBoxCircleMedium":
            Cursor = new Cursor("CursorCircleMedium.cur");
            break;
        case "picBoxCircleSmall":
            Cursor = new Cursor("CursorCircleSmall.cur");
            break;
        case "picBoxRecBig":
            Cursor = new Cursor("CursorRectBig.cur");
            break;
        case "picBoxRecMedium":
            Cursor = new Cursor("CursorRectMedium.cur");
            break;
        case "picBoxRecSmall":
            Cursor = new Cursor("CursorRectSmall.cur");
            break;
    }
} 

The files *.cur were created using images edited by myself. All the implementation is very simple but I think that there are some small tips that may be useful for someone. I hope you enjoy this!

History

  • 7th November, 2006: Initial post

License

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

About the Author

mosquets

Web Developer

Cuba Cuba

Member



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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmembermanoj kumar choubey21:17 26 Feb '12  
Generalgreat but cant use for paint Pinmemberadhi setyawan13:40 14 Apr '10  
Generalcursor PinmemberMember 68524154:20 12 Jan '10  
Generalthanks for the great article Pinmemberjas0n2317:58 29 Apr '09  
GeneralProblem with the solution PinmemberMember 370506310:48 1 Jul '08  
GeneralPaint Functionalities Pinmemberbsundarapandian0:07 6 Mar '07  
GeneralViva el Diego carajo!!! PinmemberCastorTiu14:00 9 Nov '06  

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 7 Nov 2006
Article Copyright 2006 by mosquets
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid