Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

images and drawing.

Status
Not open for further replies.

alanshort

Programmer
Jan 23, 2004
5
GB
hi

I would like to load an image from file, draw on it and save it as a different file. Something like this....


public static void updateWeatherMap ()
{
Image weatherMap = Image.FromFile (@"outputMap/weathermap.gif");

Pen bluePen = new Pen (Color.Blue, 3);

//this is the bit that doesn't work - but you get the idea//
weatherMap.DrawRectangle(bluePen,0,0,30,30);

weatherMap.Save(@"outputMap/weathermap1.gif",ImageFormat.Gif);

}

however, it doesn't work.

Any ideas ?

cheers
A
 
Hi,

You must first create a Graphics object to perform your drawing. Take a look at System.Drawing.Graphics in the .NET framework.

Try this:


public static void updateWeatherMap ()
{

Graphics g;
Image weatherMap = Image.FromFile (@"outputMap/weathermap.gif");

g = Graphics.FromImage(I);//Image type must not be compressed(try uncompressed bmp, no gif)

Pen bluePen = new Pen (Color.Blue, 3);

//this is the bit that doesn't work - but you get the idea//
g.DrawRectangle(bluePen,0,0,30,30);

weatherMap.Save(@"outputMap/weathermap1.gif",ImageFormat.Gif);

g.Dispose();
weatherMap.Dispose();

}


If you ever succeed in drawing on a compressed image format please tell me, I would be interested to know how.
 

thanks caudet, just what i was looking for.

cheers
A
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top