Asp.net Image控件显示Bitmap生成图像

   using(Bitmap bmp=new Bitmap(300,50))
        {
            using(Graphics g=Graphics.FromImage(bmp))
            {
                g.Clear(Color.WhiteSmoke);
                g.DrawString("字符串", new Font("隶书", 40), Brushes.Red, new PointF(50, 0));
                g.DrawEllipse(new Pen(Color.Green, 2), 10, 10, 10, 10);
            }
            using(System.IO.MemoryStream ms=new System.IO.MemoryStream())
            {
                bmp.Save(ms,System.Drawing.Imaging.ImageFormat.Png);
                string base64 = Convert.ToBase64String(ms.ToArray());
                Image1.ImageUrl = "data:image/png;base64,"+base64;
            }
        }

 

你可能感兴趣的:(C#)