title: File Lock After Using Graphics
body: <p>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: <strong>The action can't be completed because the file is opened in iisexpress.</strong>
  How to unlock the file after drawing ?</p>
  
  <p>Code:</p>
  
  <pre><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);
                          }
                      }
                  }
  </code></pre>