c#如何bitmap.Save(Response.OutputStream)

时间:2018-06-13 17:54:22

标签: c#

有人可以告诉我为什么这张照片不会在浏览器上流失 只是我想用我的自定义ttf写出图像并在浏览器上显示它 不想将其保存在服务器上

protected void Button1_Click(object sender, EventArgs e)
{

    string fontName = "sky-bold.ttf";

    PrivateFontCollection pfcoll = new PrivateFontCollection();
    //put a font file under a Fonts directory within your application root
    pfcoll.AddFontFile(Server.MapPath("~/Fonts/" + fontName));
    FontFamily ff = pfcoll.Families[0];
    string firstText = Label1.Text;


    PointF firstLocation = new PointF(233f, 730f);

    //put an image file under a Images directory within your application root
    string imageFilePath = Server.MapPath("~/HappyEid.jpg");
    Bitmap bitmap = (Bitmap)System.Drawing.Image.FromFile(imageFilePath);//load the image file

    using (Graphics graphics = Graphics.FromImage(bitmap))
    {
        using (Font f = new Font(ff, 30, FontStyle.Bold))
        {

            graphics.DrawString(firstText, f, Brushes.SaddleBrown, firstLocation);

        }
    }
    bitmap.Save(Response.OutputStream, ImageFormat.Png);
    } 
}

0 个答案:

没有答案