首页 > 解决方案 > c# 如何 bitmap.Save(Response.OutputStream)

问题描述

有人可以告诉我为什么这张图片不在浏览器上输出只是我想用我的自定义 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);
    } 
}

标签: c#

解决方案


推荐阅读