I am trying to crete a gif file with transparent backcolor on the fly but it
seems that GDI refuses to do this.
I am using samples from Bob Powell but it doesn't seem to work.
First create a Bitmap
public Bitmap MakeImage(strin g Text, SizeF Sf)
{
int width = (int)(Sf.Width) +2;
int height = (int)(Sf.Height )+2;
Bitmap imageObj = new Bitmap(width, height);
Graphics graphicsObj = Graphics.FromIm age(imageObj);
// Create a border in the color of the font
//graphicsObj.Fil lRectangle(new SolidBrush(_Fon tColor), 0, 0, width,
height);
// Create a LightBlue background
graphicsObj.Fil lRectangle(new SolidBrush(_Bac kgroundColor), 0, 0, width,
height);
// Specify the font and alignment
Font fontBanner = new Font(_FontFace, _FontSize, _FontStyle );
// center align the advertising pitch
StringFormat stringFormat = new StringFormat();
stringFormat.Al ignment = StringAlignment .Center;
stringFormat.Li neAlignment = StringAlignment .Center;
// Draw the adverising pitch
graphicsObj.Dra wString(Text, fontBanner, new SolidBrush(_Fon tColor), new
Rectangle(0, 0, width, height), stringFormat);
return imageObj;
}
Then save it as gif
imMail.Save(imF ileName, System.Drawing. Imaging.ImageFo rmat.Gif);
imMail.Dispose( );
Then reload and convert it to transparent background
imMail= new Bitmap(imFileNa me);
Bitmap bm = img.Convert2Gif (imMail);
if (bm != null)
{
imMail.Dispose( );
System.IO.File. Delete(imFileNa me);
bm.Save(imFileN ame, System.Drawing. Imaging.ImageFo rmat.Gif);
bm.Dispose();
}
Here is the convert
imMail= new Bitmap(imFileNa me);