473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VC# - Drawing an Image to a Control

I have a picturebox (imgViewer) which is displaying an image. Now i want to display another image (a smaller one) on top of this image. This is what i was doing:

private void btn_Path_Click(object sender, EventArgs e)
{
Bitmap path = new Bitmap(@"C:\Engg\Path.JPG");
Graphics graph = this.imgViewer.CreateGraphics();

graph.DrawImage(path, 0, 0);

graph.Dispose();
}


But nothing happens when i push my button (btn_Path). But when i change the code to draw on my form (instead of my picturebox), it works:

Graphics graph = this.CreateGraphics();

it properly paints on the form. What is wrong????? How can I paint on my picturebox which is already displaying an image?
Dec 21 '07 #1
3 1357
you need to redraw the same image again, see the sample code below

Bitmap newbmp = new Bitmap(bmpCropped, 160, 125);
Graphics g = Graphics.FromImage(newbmp);
ImageAttributes attributes = new ImageAttributes();
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(newbmp, new Rectangle(photo_x, photo_y, photo_wdh, photo_hgt), photo_x, photo_y,newbmp.Width, newbmp.Height, GraphicsUnit.Pixel, attributes);
Dec 21 '07 #2
Plater
7,872 Expert 4TB
It's possible that the button's paint() function is being called and it's redrawing itself. (which does not include your picture)

You would probably have to override the controls paint function OR attach your own listener to its paint event.
Then you could draw your image in there after it draws itself.
Dec 21 '07 #3
hey i managed to find a simple solution:

private void btn_Path_Click(object sender, EventArgs e)
{
Bitmap path = new Bitmap(@"C:\Engg\Path.JPG");
Graphics graph = Graphics.FromImage( this.imgViewer.Image );
graph.DrawImage(path, 0, 0);

graph.Dispose();
}

thanks everyone!
Dec 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: zengou | last post by:
My application have many picturebox objects,when run it ,sometimes i will have a strange error,how to work out ,help me please!(in windows98,the error cause frequently than in windowsxp) ...
2
by: Champika Nirosh | last post by:
Hi, I want to create drawing board application that can draw Line, rectagle, circle and free hand drawing. Each drawing need to be transparent, moveable (draggable), have bring to front and...
3
by: Alberto | last post by:
I'm drawing an image in a panel control with this sentence in the Paint method: e.Graphics.DrawImageUnscaled(Image, panelImage.AutoScrollPosition); The problem is that I only want to paint a...
0
by: borhan | last post by:
I am designing a program in which the user will be drawing, lines, circules and so on, on a paint control which displays an image opened by the user. "It's like there is a map on the picturebox...
7
by: Marc Pelletier | last post by:
Hello all, I have a class which includes a method to create a chart. I want to be able to call this method from asp.net code as well as windows application code, so I have sketched it out as...
2
by: Tyler Foreman | last post by:
Hello, I had an earlier post regarding a strange exception I (thought) I was getting in my windows form. I have since been able to trace the problem to a picturebox control on my form. I can...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
9
by: Eric | last post by:
Hi Everyone, I'm writing a UserControl that exposes a property of the type System.Drawing.Image, like this: Public Property DefaultImage() As Image Get Return propDefaultImage End Get...
5
by: Macias | last post by:
Hi, Please help me, how I can make a line drawing on PictureBox similar to MS paint. I thinking about this: click and hold button, move mouse and relase button. I'm trying useing this...
2
by: ThatsIT.net.au | last post by:
I have this code that writes a pie chart in a asp.net page, but I want to use it in a server control. When I try I get a error on the last line "Response.OutputStream" Obviously there is no...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.