In this example I use True Type Font (ttf) file. When i use DrawString method of the Graphics object it locks the file and it says: The action can't be completed because the file is opened in iisexpress. How to unlock the file after drawing ?
Code:
using (Font a = new Font(pfc.Families[0], points))
{
using (Bitmap codeBitmap = new Bitmap(1, 1, PixelFormat.Format24bppRgb))
{
using (Graphics g = Graphics.FromImage(codeBitmap))
{
size = g.MeasureString(code, a);
}
}
using (Bitmap codeBitmap = new Bitmap((int)size.Width, (int)size.Height, PixelFormat.Format24bppRgb))
{
using (Graphics g = Graphics.FromImage(codeBitmap))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
g.Clear(Color.White);
g.DrawString(code, a, Brushes.Black, 0, 0); //It locks the file here
codeBitmap.Save(response.OutputStream, ImageFormat.Gif);
}
}
}