日期:2014-05-19  浏览次数:20853 次

picturebox中加载了一个图片,我想把这个图片用代码更新,可是运行这段代码时说图片正在使用,请问怎么解决.谢谢
MemoryStream   s   =   new   MemoryStream();
Image   img   =   Image.FromFile(file);
Graphics   graphics   =   Graphics.FromImage(img);
graphics.FillRectangle(Brushes.White,   new   Rectangle(0,   0,   img.Width,   img.Height));
graphics.SmoothingMode   =   SmoothingMode.HighQuality;
int   nlen   =   System.Text.Encoding.Default.GetByteCount(logo);
graphics.DrawString(logo,   new   Font( "Arial ",   52,   GraphicsUnit.Pixel),   Brushes.Black,   new   Point(x,   y));
img.Save(s,   img.RawFormat);
graphics.Dispose();
img.Dispose();
**FileStream   fi   =   new   FileStream(file,   FileMode.Open,   FileAccess.ReadWrite);
s.WriteTo(fi);
s.Close();
fi.Close();
带**的那行抛的异常.请高手指教.


------解决方案--------------------
AttachLogoOnBitmap( "C:\\abc.jpg ",textBox1.Text, "Text ",40,40);
Byte[] bytBLOBData = new Byte[s.Length];
s.Position = 0;
s.Read(bytBLOBData, 0, Convert.ToInt32(s.Length));
MemoryStream stmBLOBData = new MemoryStream(bytBLOBData);
pictureBox1.Image= Image.FromStream(stmBLOBData);