使用图形后文件锁定

时间:2014-12-11 07:32:30

标签: c# graphics gdi

在此示例中,我使用True Type Font(ttf)文件。当我使用Graphics对象的DrawString方法时,它会锁定文件并显示:由于文件是在iisexpress中打开的,因此无法完成操作。 如何在绘图后解锁文件?

代码:

                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);
                        }
                    }
                }

0 个答案:

没有答案