1
Answer

Can you resize image stored as blob in a handler?

Debra Fry

Debra Fry

13y
3.6k
1
I have a blob field which holds a jpeg for each record in the table.  I have a handler that outputs the image to the webpage.

All this works ok, however, I would like to be able to resize the image before it is displayed in the webpage.

Is this possible? If yes, could you point me in the right direct.

Many thanks
:)

Here is the code for the handler:

using System;
using System.Web;
using System.IO;

public class Handler2 : IHttpHandler {
   

    public bool IsReusable {
        get {
            return false;
        }
    }

    public void ProcessRequest(HttpContext context)
    {
        // Set up the response settings
        context.Response.ContentType = "image/jpeg";
        //context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.BufferOutput = false;

        // Setup the PhotoID Parameter
        Int32 id = -1;
        Stream stream = null;

            id = Convert.ToInt32(context.Request.QueryString["ProfileId"]);
            stream = ProfileManager.GetPhoto(id);

        // Write image stream to the response stream
        const int buffersize = 1024 * 16;
        byte[] buffer = new byte[buffersize];
        int count = stream.Read(buffer, 0, buffersize);
        while (count > 0)
        {
            context.Response.OutputStream.Write(buffer, 0, count);
            count = stream.Read(buffer, 0, buffersize);
        }
    }

}
Answers (1)