A Generic error occurs at GDI+ at Bitmap.Save() after using SaveFileDialog

前端 未结 12 1522
情书的邮戳
情书的邮戳 2020-12-10 01:07

I use the following code block with some more code inside the using block:

using (System.Drawing.Bitmap tempImg =
       (System.Drawing.Bitmap)tempObj.GetDa         


        
12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 01:41

    This is code sample from Microsoft Forums.

    // new image with transparent Alpha layer
    using (var bitmap = new Bitmap(330, 18, PixelFormat.Format32bppArgb))
    {
        using (var graphics = Graphics.FromImage(bitmap))
        {
            // add some anti-aliasing
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
    
            using (var font = new Font("Arial", 14.0f, GraphicsUnit.Pixel))
            {
                using (var brush = new SolidBrush(Color.White))
                {
                    // draw it
                    graphics.DrawString(user.Email, font, brush, 0, 0);
                }
            }
        }
    
        // setup the response
        Response.Clear();
        Response.ContentType = "image/png";
        Response.BufferOutput = true;
    
        // write it to the output stream
        bitmap.Save(Response.OutputStream, ImageFormat.Png);
        Response.Flush();
    }
    

提交回复
热议问题