Click here to Skip to main content
12,816,406 members (31,016 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 7 Nov 2006

Very Simple Paint

, 7 Nov 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Painting with different colors into the images
Sample Image - sources_very_simple_paint.jpg


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.

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

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!


  • 7th November, 2006: Initial post


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


About the Author

Web Developer
Cuba Cuba
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionMessage Removed Pin
Member 1230832816-Feb-16 23:42
memberMember 1230832816-Feb-16 23:42 
AnswerVote of thanks & crash solved Pin
Ritesh bagalkoti4-Aug-14 21:48
memberRitesh bagalkoti4-Aug-14 21:48 
GeneralMy vote of 5 Pin
manoj kumar choubey26-Feb-12 22:17
membermanoj kumar choubey26-Feb-12 22:17 
Generalgreat but cant use for paint Pin
adhi setyawan14-Apr-10 14:40
memberadhi setyawan14-Apr-10 14:40 
GeneralRe: great but cant use for paint Pin
S.M. Zamshed Farhan14-Jan-13 22:13
memberS.M. Zamshed Farhan14-Jan-13 22:13 
Generalcursor Pin
Member 685241512-Jan-10 5:20
memberMember 685241512-Jan-10 5:20 
Generalthanks for the great article Pin
jas0n2329-Apr-09 18:58
memberjas0n2329-Apr-09 18:58 
GeneralProblem with the solution Pin
Member 37050631-Jul-08 11:48
memberMember 37050631-Jul-08 11:48 
GeneralPaint Functionalities Pin
bsundarapandian6-Mar-07 1:07
memberbsundarapandian6-Mar-07 1:07 
GeneralViva el Diego carajo!!! Pin
CastorTiu9-Nov-06 15:00
memberCastorTiu9-Nov-06 15:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 7 Nov 2006
Article Copyright 2006 by mosquets
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid