How to generate a bitmap dynamically in ASP.NET?

There are two steps in this process

Step1: Create the bitmap dynamically

private Bitmap GetDynamicBitmap()

{

Bitmap bitmap = new Bitmap(100, 100);

      Graphics graphics = Graphics.FromImage(bitmap);

      graphics.DrawString("Dynamic Bitmap", new Font("Calibri", 14, FontStyle.Bold), Brushes.Black,

      new PointF(10, 10));

 

      return bitmap;

}            

Step2: Set the http response to bitmap

Bitmap bitmap = GetDynamicBitmap();

context.Response.ContentType = "image/bmp";

bitmap.Save(context.Response.OutputStream, ImageFormat.Bmp);

Leave a Reply

Your email address will not be published. Required fields are marked *