Click here to Skip to main content
15,743,541 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to open a image file(.JPG,.BMP etc) in a Picture box and than i want to create shapes on that images so is it possible with DrawTools project?

1 solution

First of all, don't even play with the idea of using PictureBox.

This control is poorly redundant and should be used only to simplify the simplest cases, such as showing some static image. In most more complex cases, it only presents hassles and use resources giving nothing in return. You should use your own rendering of graphics, which is really simple. Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].

Now, to draw on a bitmap, you need to obtain the instance of System.Drawing.Graphics from this bitmap. This is how:[^].

Now, you can use this image in a usual way, to draw on a bitmap.

Again, check your design thoroughly. If the only purpose of drawing on a bitmap was drawing on screen, you don't even need a bitmap. The bitmap will be used internally to avoid flicker, if you simply use double buffering. On further rendering detail, please see my past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my application?[^].

If you still need to draw on a bitmap (for example, if you need to save graphics as bitmap), do as I explained before. But if you need to draw on both (bitmap, screen, maybe printer as well), pay attention that they all use System.Drawing.Graphis. Write some universal method using Graphics as a parameter, with other parameters, such as size. This way, you can abstract out your rendering from a particular media.

Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900