2

how i can cast the http handler response to image.
I have created a handler which gives as follow which does some manipulation in the image


var absolutePath = context.Server.MapPath(imagePath);
var originalImage = Image.FromFile(absolutePath);
originalImage = new ImageMethods().AddWatermarkText(originalImage, "One Click");
context.Response.ContentType = "image/jpeg";
originalImage.Save(context.Response.OutputStream, ImageFormat.Jpeg);   

Zoidberg
  • 10,137
  • 2
  • 31
  • 53
शेखर
  • 17,412
  • 13
  • 61
  • 117

1 Answers1

3

The cast must be binary i.e byte array.

I think you are looking for something like this in handler

    public void ProcessRequest (HttpContext context)
    {
        context.Response.ContentType = "text/image"; ;
        System.IO.Stream strm = ShowImage(Number);


        if (strm != null)
        {
           byte[] buffer = new byte[100000];
           strm.Read(buffer, 0, buffer.Length);
           context.Response.OutputStream.Write(buffer, 0, buffer.Length);
        }
    }
SheetJS
  • 22,470
  • 12
  • 65
  • 75
Dinesh
  • 3,652
  • 2
  • 25
  • 35