W
WT
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(string Text, SizeF Sf)
{
int width = (int)(Sf.Width)+2;
int height = (int)(Sf.Height)+2;
Bitmap imageObj = new Bitmap(width, height);
Graphics graphicsObj = Graphics.FromImage(imageObj);
// Create a border in the color of the font
//graphicsObj.FillRectangle(new SolidBrush(_FontColor), 0, 0, width,
height);
// Create a LightBlue background
graphicsObj.FillRectangle(new SolidBrush(_BackgroundColor), 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.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
// Draw the adverising pitch
graphicsObj.DrawString(Text, fontBanner, new SolidBrush(_FontColor), new
Rectangle(0, 0, width, height), stringFormat);
return imageObj;
}
Then save it as gif
imMail.Save(imFileName, System.Drawing.Imaging.ImageFormat.Gif);
imMail.Dispose();
Then reload and convert it to transparent background
imMail= new Bitmap(imFileName);
Bitmap bm = img.Convert2Gif(imMail);
if (bm != null)
{
imMail.Dispose();
System.IO.File.Delete(imFileName);
bm.Save(imFileName, System.Drawing.Imaging.ImageFormat.Gif);
bm.Dispose();
}
Here is the convert
imMail= new Bitmap(imFileName);
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(string Text, SizeF Sf)
{
int width = (int)(Sf.Width)+2;
int height = (int)(Sf.Height)+2;
Bitmap imageObj = new Bitmap(width, height);
Graphics graphicsObj = Graphics.FromImage(imageObj);
// Create a border in the color of the font
//graphicsObj.FillRectangle(new SolidBrush(_FontColor), 0, 0, width,
height);
// Create a LightBlue background
graphicsObj.FillRectangle(new SolidBrush(_BackgroundColor), 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.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
// Draw the adverising pitch
graphicsObj.DrawString(Text, fontBanner, new SolidBrush(_FontColor), new
Rectangle(0, 0, width, height), stringFormat);
return imageObj;
}
Then save it as gif
imMail.Save(imFileName, System.Drawing.Imaging.ImageFormat.Gif);
imMail.Dispose();
Then reload and convert it to transparent background
imMail= new Bitmap(imFileName);
Bitmap bm = img.Convert2Gif(imMail);
if (bm != null)
{
imMail.Dispose();
System.IO.File.Delete(imFileName);
bm.Save(imFileName, System.Drawing.Imaging.ImageFormat.Gif);
bm.Dispose();
}
Here is the convert
imMail= new Bitmap(imFileName);