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();
带**的那行抛的异常.请高手指教.

解决方案 »

  1.   

    也遇到过类似问题在Image img = Image.FromFile(file);  时文件已经打开了所以new FileStream(file, FileMode.Open, FileAccess.ReadWrite);报错可以考虑先用读文件的方式打开文件读取图片,之后关闭文件再做其它操作
      

  2.   

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