473,411 Members | 2,185 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,411 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 3069
> 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...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.