I have the following code, which takes a string and adds it to a Bitmap in memory, which in turn is saved as a BMP file. The code I have at the moment is as follows;
string sFileData = "Hello World";
string sFileName = "Bitmap.bmp";
Bitmap oBitmap = new Bitmap(1,1);
Font oFont = new Font("Arial", 11, FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
int iWidth = 0;
int iHeight = 0;
using (Graphics oGraphics = Graphics.FromImage(oBitmap))
{
oGraphics.Clear(Color.White);
iWidth = (int)oGraphics.MeasureString(sFileData, oFont).Width;
iHeight = (int)oGraphics.MeasureString(sFileData, oFont).Height;
oBitmap = new Bitmap(oBitmap, new Size(iWidth, iHeight));
oGraphics.DrawString(sFileData, oFont, new SolidBrush(System.Drawing.Color.Black), 0, 0);
oGraphics.Flush();
}
oBitmap.Save(sFileName, System.Drawing.Imaging.ImageFormat.Bmp);
The problem I have is when I view the BMP file in Paint, the size of the bitmap is defined correctly, the background is white, however their is no text ?
What am I doing wrong ?