Auto Expand Images

M

MikeB

I currently use the below code to display images from my database. Part of
what my site allows is for users to click on an image and I open up my
handler.ashx to display the image. Is there a way to make the image always
be displayed in full size? Users of my site dont realize that you can
either click the image to make it go full size or click the icon in the
lower right part of the image when you mouse over it to expand it.

TIA
public class Handler : IHttpHandler {

public bool IsReusable {

get {

return true;

}

}


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 Size Parameter

// Setup the PhotoID Parameter

Int32 id = -1;

Stream stream = null;

string originalsize = "O";

if(context.Request.QueryString["Size"] != null &&
context.Request.QueryString["Size"] != "")

{

originalsize = context.Request.QueryString["Size"];

}


if (context.Request.QueryString["PhotoID"] != null &&
context.Request.QueryString["PhotoID"] != "")

{

id = Convert.ToInt32(context.Request.QueryString["PhotoID"]);

stream = PhotosService.GetPhoto(id, originalsize);

}

else

{

id = Convert.ToInt32(context.Request.QueryString["ProductID"]);

stream = PhotosService.GetFirstPhoto(id,
Convert.ToInt32(context.Request.QueryString["CompanyID"]), originalsize);

}

// Get the photo from the database, if nothing is returned, get the default
"placeholder" photo

if (stream == null)

{

stream = new
FileStream(HttpContext.Current.Server.MapPath("~/Images/placeholder-200.jpg"),
FileMode.Open, FileAccess.Read, FileShare.Read);

}

// 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);

}


}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top