473,229 Members | 1,802 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,229 software developers and data experts.

Drawing on existing image

Hi

I want to allow the user to drow some locators on an image and connect
the locators with lines. So I tried to put the following code in the
onmousedown enevt of the picture:
Graphics LGraphics = Graphics.FromImage(imgMap.Image);
LGraphics.DrawString("X", new Font("Arial", 12),
SystemBrushes.WindowText, AX, AY);
Pen LPen = new Pen(System.Drawing.Color.Black);
LPen.Brush = SystemBrushes.WindowText;
if ((FLastX >= 0) && (FLastY >= 0))
{
LGraphics.DrawLine(LPen, FLastX, FLastY, AX, AY);
}
LGraphics.Save();
FLastX = AX;
FLastY = AY;

The really annoying thing is
1) I can't use this code for indexed bitmaps
2) Nothing appears on the image

My questions are:
1) How do I set the color for the text to be shown ("X" in my case)?
2) How should I draw on all types of bitmaps?
and of course
3) What to do so my text and my lines become visible on the bitmap?
Note: imgMap.Image is of type System.Drawing.Image and loaded with a
bitmap.

Thanks in advance for any help !

Christina Androne
Nov 15 '05 #1
4 3059
> The really annoying thing is
1) I can't use this code for indexed bitmaps You can only get a graphics object for a 24 or 32 bit image.
2) Nothing appears on the image It does, you just don't see it.

My questions are:
1) How do I set the color for the text to be shown ("X" in my case)? You've done it correctly
2) How should I draw on all types of bitmaps? You'll have to determine if an image is indexed, if it is, create a non
indexed image of the same size and draw the image followed by the text to
that image. Then, you can save to an indexed image later if you wish.
and of course
3) What to do so my text and my lines become visible on the bitmap?
Graphics.Save has nothing to do with saving the image.

First refresh the picture (I assume you're using picturebox so
pictureBox1.Invalidate() will do that. Then you can save the bitmap such as
imgmap.Image.Save(<filename>,<fileFormat>).

--
Bob Powell [MVP]
C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Christina Androne" <ac********@NotAtHome.ro> wrote in message
news:uV**************@tk2msftngp13.phx.gbl... Hi

I want to allow the user to drow some locators on an image and connect
the locators with lines. So I tried to put the following code in the
onmousedown enevt of the picture:
Graphics LGraphics = Graphics.FromImage(imgMap.Image);
LGraphics.DrawString("X", new Font("Arial", 12),
SystemBrushes.WindowText, AX, AY);
Pen LPen = new Pen(System.Drawing.Color.Black);
LPen.Brush = SystemBrushes.WindowText;
if ((FLastX >= 0) && (FLastY >= 0))
{
LGraphics.DrawLine(LPen, FLastX, FLastY, AX, AY);
}
LGraphics.Save();
FLastX = AX;
FLastY = AY;

The really annoying thing is
1) I can't use this code for indexed bitmaps
2) Nothing appears on the image

My questions are:
1) How do I set the color for the text to be shown ("X" in my case)?
2) How should I draw on all types of bitmaps?
and of course
3) What to do so my text and my lines become visible on the bitmap?
Note: imgMap.Image is of type System.Drawing.Image and loaded with a
bitmap.

Thanks in advance for any help !

Christina Androne

Nov 15 '05 #2
Bob Powell [MVP] wrote:
2) How should I draw on all types of bitmaps? You'll have to determine if an image is indexed, if it is, create a
non indexed image of the same size and draw the image followed by the
text to that image. Then, you can save to an indexed image later if
you wish.


Can you please tell me how do I create the nonindexed image ? Can I do
this programatically or I have to use an image editor?
and of course
3) What to do so my text and my lines become visible on the bitmap?


First refresh the picture (I assume you're using picturebox so
pictureBox1.Invalidate() will do that. Then you can save the bitmap
such as imgmap.Image.Save(<filename>,<fileFormat>).


Well, I am not using picture box ... and I can't save the bitmap to a
file. Is there any way to refresh a bitmap ... if that makes sense ..

Nov 15 '05 #3
You can create the non indexed image like this..

Bitmap bm1=(Bitmap)Image.FromFile("doodaa.gif");
Bitmap bm2=new Bitmap(bm1.Width,bm1.Height);
Graphics g=Graphics.FromImage(bm2);
g.DrawImageUnscaled(bm1,0,0);
//bm2 now contains a non-indexed version of the image.
//Now draw the X..
g.DrawLine(blah-blah....);
g.DrawLine(blah-blah....);
//get rid of the graphics
g.Dispose();
//and save a new gif
bm2.Save("foobar.gif",ImageFormat.Gif);

--
Bob Powell [MVP]
C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Christina Androne" <ac********@NotAtHome.ro> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Bob Powell [MVP] wrote:
2) How should I draw on all types of bitmaps?

You'll have to determine if an image is indexed, if it is, create a
non indexed image of the same size and draw the image followed by the
text to that image. Then, you can save to an indexed image later if
you wish.


Can you please tell me how do I create the nonindexed image ? Can I do
this programatically or I have to use an image editor?
and of course
3) What to do so my text and my lines become visible on the bitmap?


First refresh the picture (I assume you're using picturebox so
pictureBox1.Invalidate() will do that. Then you can save the bitmap
such as imgmap.Image.Save(<filename>,<fileFormat>).


Well, I am not using picture box ... and I can't save the bitmap to a
file. Is there any way to refresh a bitmap ... if that makes sense ..

Nov 15 '05 #4
Bob Powell [MVP] wrote:
You can create the non indexed image like this..

Bitmap bm1=(Bitmap)Image.FromFile("doodaa.gif");
Bitmap bm2=new Bitmap(bm1.Width,bm1.Height);
Graphics g=Graphics.FromImage(bm2);
g.DrawImageUnscaled(bm1,0,0);
//bm2 now contains a non-indexed version of the image.
//Now draw the X..
g.DrawLine(blah-blah....);
g.DrawLine(blah-blah....);
//get rid of the graphics
g.Dispose();
//and save a new gif
bm2.Save("foobar.gif",ImageFormat.Gif);


Thank you,

Christina Androne
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Remon Huijts | last post by:
Hi there, For a very specific service, I have created a PHP script that uses the GD library functions to create a PNG image from a few lines of XML data describing a simple diagram/drawing. It's...
19
by: Atif | last post by:
Hello all, In my html page I want to add an image say of 800x600. Now I want that when ever I am given two coordinates on this image say (x1, y1)=(50, 100) and (x2, y2)=(200, 300), the java script...
1
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to...
7
by: Toby Mathews | last post by:
Hi, In an ASP.Net application I want to convert open create a FileStream object from a System.Drawing.Image - is this possible? I create an instance of an Image object using the FromFile method,...
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...
5
by: Jerry J | last post by:
I want to use the System.Drawing.Image class. According to the help file, this is an abstract base class. Because it is supposedly abstract, I created another class that inherits from it. However,...
3
by: Dave Keen | last post by:
Hi all. Hope you can help me. This should be easy but I can't make this work. In brief I am building a page of thumbnails using images held in a SQLServer 2000 database. I do this by creating...
2
by: luckyguy4ru | last post by:
Hello every body, I just joined today this forum hopping that i will get really good help here, My final project is to refashioned an artist work which is mostly pencil work, i have fake color...
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.