繁体   English   中英

不保存新的位图C#

[英]Not saving a new bitmap c#

我想显示创建的新位图图像。 不保存。

我在C#中将位图与图形一起使用,并希望返回新图像而不必保存新图像。

C#

private void GenerateBanner( string titleText ) {

    Bitmap bannerSource = new Bitmap( DefaultBannerPath );
    //bannerSource.Save( PhysicalBannerPath );
    RectangleF rectf = new RectangleF( 430, 50, 650, 50 );

    using (Graphics g = Graphics.FromImage(bannerSource))
    {
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
        g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
        g.DrawString(titleText, new Font("Bradley Hand ITC", 100, FontStyle.Bold), Brushes.White, rectf);
        //bannerSource.Save( PhysicalBannerPath );
    }
}

要从ASPX页面返回该图像(可以在HTML中用作img src ),则需要使用MemoryStream并将其转换为byte[] 然后使用Response.BinaryWrite方法:

        byte[] bytes;
        using (var stream = new System.IO.MemoryStream())
        {
            bannerSource.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
            bytes = stream.ToArray();
        }

        Response.ContentType = "image/jpeg";
        Response.Clear();
        Response.BinaryWrite(bytes);
        Response.End();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM