C# .NET - How to draw on top of an image? PocketPC application

Asked By Farah Nisar on 28-Mar-09 07:23 AM

Hi !

I am developing a PocketPC application in C#.
I have an image set in the back ground and I want to draw with a mouse on top of it. After writing, I want to store that image separately in some bmp format.
 
How do i draw something on top of the image? I have been able to write on my form, but writing on the image remains a problem.
 
Thanx in advance.
Farah Nisar. 
 
 

Hmm, think I'd do this to keep it simple - Robbe Morris replied to Farah Nisar on 28-Mar-09 12:41 PM

Draw a transparent image over the top of your BitMapImage.  Over the top, not draw on the BitMapImage itself.  I'd let my mouse draw on the transparent image and save it.

You could also do something similar to my handwritten signature example:

http://www.eggheadcafe.com/articles/dotnetcompactframework_capture_signature_to_file.asp


Programmatically add text to an image - mv ark replied to Farah Nisar on 28-Mar-09 09:29 PM

Adapt this snippet -

<%@ Page language="C#" ContentType="image/jpeg"%> 
<%@ Import Namespace="System.Drawing" %> 
<%@ Import Namespace="System.Drawing.Imaging" %> 
<%@ Import Namespace="System.IO" %> 
<script runat="server"> 
void Page_Load(Object o, EventArgs e) 
{ 
String FileName = "image1.jpg"; 
String Message = "Season's Greetings"; 
Color FillColor = Color.FromArgb(127,255,255,255); 
SolidBrush FillBrush = new SolidBrush(FillColor); 
Rectangle FillRectangle = new Rectangle(5,5,310,50); 

Font TextFont = new Font("Comic Sans MS",20); 
SolidBrush TextBrush = new SolidBrush(Color.Navy); 
StringFormat TextFormat = new StringFormat(); 
TextFormat.Alignment = StringAlignment.Center; 
TextFormat.LineAlignment = StringAlignment.Center; 
System.Drawing.Image GreetingImage = System.Drawing.Image.FromFile(Server.MapPath("images") + "\\" + FileName); 
Graphics DrawingSurface = Graphics.FromImage(GreetingImage); 
DrawingSurface.FillRectangle(FillBrush, FillRectangle); 
DrawingSurface.DrawString(Message, TextFont, TextBrush, FillRectangle, TextFormat); 
Stream Output = Response.OutputStream; 
GreetingImage.Save(Output,ImageFormat.Jpeg); 
} 
</script>


Source:
http://mvark.blogspot.com/2004/12/code-programmatically-add-text-to.html

Making the image transparent... - Farah Nisar replied to Robbe Morris on 31-Mar-09 01:01 PM


thnx for ur help...
Actually that is exavtly what i want to do....draw a transparent image with my mouse over the top of the BitMapImage. But how do i make an image transparent?? Should i make the picture box transparent somehow??
I think that would be the best approach, making the picture box look transparent, so that i can see the bitmap image behind it, and at the same time draw on the pic box n save it separately.

And the second thing is that i didnt really get how u set the image "signhere.png" to the panel in the example u reffered to. Hope u would help me. Waiting for some solution.

Regards,
Farah Nisar.
The picturebox has a .BackGroundColor property - Robbe Morris replied to Farah Nisar on 31-Mar-09 01:13 PM

Set that to be System.Drawing.Color.Transparent

The SignatureControl in that application inherits from control.  In the form, I just added it to the collection of controls on the form at runtime.


BackColor Property for Picture Boxes. - Farah Nisar replied to Robbe Morris on 31-Mar-09 02:30 PM
I tried to set the BackColor property of the picture box like below.
But as i try to set the back color to Color.Transparent, it gives me an error message stating "Property value is not valid for the Control."
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(56, 51);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(173, 160);
this.pictureBox1.BackColor = System.Drawing.Color.Transparent;

Derek Hudson replied to Farah Nisar on 21-Mar-14 03:56 AM
Sounds like image annotation to me when you want to draw on top of an image  :) Anyway, you can try this to draw images on images. Hope it'll help. It's in VB.NET, so you might wanna convert to C# first.

http://www.yiigo.com/guides/vbnet/how-to-image-drawing.shtml