|
| |||||||||
| Tags: graphic design, image, photo, picture, sql |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How to draw picture via coding I want to draw a picture. This is the first time I set foot in this area (more used to SQL and co). So I see 2, 3 stuff on the net ... But ... (yes there is always a but ...) I use the following code: Code: public Form1()
{
InitializeComponent();
bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
//bmp2 = new Bitmap(pictureBox2.Width, pictureBox2.Height);
des = Graphics.FromImage(bmp);
des2 = pictureBox2.CreateGraphics();
}
private void button1_Click(object sender, EventArgs e)
{
//routine design
des.FillRectangle(new SolidBrush(Color.DarkCyan), new Rectangle(new Point(10, 10), new Size(50, 50)));
pictureBox1.Image = bmp;
}
private void button2_Click(object sender, EventArgs e)
{
//routine design
des2.FillRectangle(new SolidBrush(Color.DarkCyan), new Rectangle(new Point(10, 10), new Size(50, 50)));
//pictureBox2.Image = bmp2;
} In the case of the picture box 2, I can define the background and graphic elements will come to position above. What I want! But the problem is at a displacement of the window offscreen, or redirect, the Element graphic picture box 1 continues, then that element of the picture box 2 disappears .. I grant you that it's probably a matter maternal 2nd year, but how to draw on my background without graphic element that disappears when handling the window? |
|
#2
| ||||
| ||||
| Re: How to draw picture via coding
Answer 1: By making the draw in the OnPaint() component Answer 2: This kind of question is "often" put on this forum, I invite you to research that will explain all good practices to achieve what you want you have done. It seems to me a tutorial on the UserControl explicit all the information you need for your creation! |
|
#3
| ||||
| ||||
| Re: How to draw picture via coding
Or we get the Paint event since you are in form and not in the component. Above all use the Graphics provided by the argument of the function. Code: protected override void OnPaint(PaintEventArgs e)
{
// Recover graphics
Graphics gfx = e.Graphics;
} Code: // Normally generate by designer
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
// Recuperation of the event
protected override void PictureBox1_Paint(Object Sender,PaintEventArgs e)
{
// Recover graphics
Graphics gfx = e.Graphics;
} In GDI+, your best friends are Using and Dispose which can release the resources that are not needed. Not those needing to gfx.dispose (), it will automatically as it is declared in function. |
|
#4
| |||
| |||
| Re: How to draw picture via coding
I'll see it. What I wish the finally that just add a point on an existing image .. one that will apply broadly after a search we show the location of the item on a map (plan). It look like X, and it shows on our map (picture) or is placed item X. There's easier, faster, why? or no ... |
|
#5
| ||||
| ||||
| Re: How to draw picture via coding
If it is to put one point (or ten, but not type 10000) Code: Bitmap img = new Bitmap("c:\...\img.bmp");
img.SetPixel ( 100,50,Color.Red); |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to draw picture via coding" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Picture size for Wallpaper picture in Sony Ericsson Xperia Play | Bryant | Portable Devices | 4 | 07-10-2011 01:24 AM |
| Making MS Office Picture Manager My Default Picture Viewer / Editor | RBoyle | MS Office Support | 2 | 09-01-2011 05:07 PM |
| Help in coding documents | Remedy | Software Development | 5 | 11-02-2010 02:34 AM |
| SANYO Introduces True HD DLP projector with “Picture-by-Picture” Capability | Abbas | Portable Devices | 2 | 11-03-2009 12:25 AM |
| how do i set microsoft picture viewer as my default picture viewe | Bob I | MS Office Support | 0 | 27-04-2007 01:49 AM |