Setting the Background of an Graphics [C#]

Shaitan00

Well-known member
Joined
Aug 11, 2003
Messages
343
Location
Hell
Given the following code:
Code:
Bitmap img = new Bitmap(nLevelWidth, nLevelHeight);
Graphics gLevel = Graphics.FromImage(img);

Bitmap imgBelow = _imgIcon;
imgBelow.MakeTransparent();
gLevel.DrawImage(imgBelow, i, j, SIZE, CELL_SIZE);

// NOW I NEED TO SET THE BACKCOLOR OF THE GRAPHICS BEFORE I PUT IT ON THE SCREEN

So, I create a new Image (img) and load its Graphics (gLevel) so I can draw on it, then I draw an Icon somewhere on it (can be anywhere, and can be any kind of Icon)...
After that is done I need to give my Image (img) a BACKCOLOR / BACKGROUND and oddly enough I cant seem to figure out how to set that property...

Any ideas, hints, and help would be greatly appreciated, thanks
 
As far as Im aware there is no simple way to change the background in the manner you describe, because quite simply there is no such thing as a background. To the best of my knowledge the bitmap object is single layer meaning that it has no way of distinguishing a difference between what you think is the background and the image. One way of doing this would be to research some of the various flood fill options, but that could potentially become complicated.

The simplest approach would be to set the background colour before drawing the imagine by calling gLevel.Clear(backCol);
 
Back
Top