Question

I'm trying to draw a string on an image and display it on a picturebox and I'm using the DrawString function in the .Net graphics library.

Problem is the function is drawing on two images - (the image that I want it to draw on, and the original image which I do not want it to draw on).

Here's the code:

Image img = new Bitmap(1, 1);  
img = original;

drawing = Graphics.FromImage(img);
Font priceFont = new Font("Calibri (Body)", 16.0f, FontStyle.Bold);

drawing.DrawString(textBox1.Text, priceFont, brush, 410f, 660);
drawing.Save();
drawing.Dispose();

pictureBox1.BackgroundImage = null;
pictureBox1.BackgroundImage = img;
pictureBox2.BackgroundImage = null;
pictureBox2.BackgroundImage = original;

picbox1 and picbox2 are displaying the same exact results as if the object 'drawing' is drawing on both images. Any ideas how I can make it draw on only the 'img' object and not 'original' too?

Was it helpful?

Solution

Image img = new Bitmap(1, 1);  
img = original;

The above two lines cause this issue.

You shoud be using it like this

Image img = new Bitmap(original);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top