You could use a control that inherits from IHttpHandler like this:
<%@ WebHandler Language="C#"
Class="AspNet.S tarterKits.Clas sifieds.Web.Pho toDisplay" %>
using System;
using System.Configur ation;
using System.Data;
using System.Drawing;
using System.Drawing. Imaging;
using System.IO;
using System.Web;
using AspNet.StarterK its.Classifieds .BusinessLogicL ayer;
namespace Mynamespace
{
public class PhotoDisplay : IHttpHandler
{
public const string QueryStringFull Size = "full";
public const string QueryStringMedi umLarge = "large";
public const string QueryStringMedi umSize = "medium";
public const string QueryStringMedi umSmall = "small";
public void ProcessRequest( HttpContext context)
{
HttpResponse Response = context.Respons e;
HttpRequest Request = context.Request ;
Image myThumbnail = new Bitmap(1,1);
//string url2 = Path.Combine(@" c:\attachments" , "110.jpg");
if (Request.QueryS tring["photoid"] != null)
{
// Retrieve the path to the file.
string url2 =
GetPicturePath( Request.QuerySt ring["photoid"],context);
if (url2.Length 0)
{
Image.GetThumbn ailImageAbort myCallback = new
Image.GetThumbn ailImageAbort(T humbnailCallbac k);
Image fullImg = Image.FromFile( url2);
if (Request.QueryS tring["size"] ==
QueryStringMedi umSmall)
myThumbnail = fullImg.GetThum bnailImage(100, 100,
myCallback, IntPtr.Zero);
if (Request.QueryS tring["size"] == QueryStringMedi umSize)
myThumbnail = fullImg.GetThum bnailImage(200, 200,
myCallback, IntPtr.Zero);
if (Request.QueryS tring["size"] == QueryStringMedi umLarge)
myThumbnail = fullImg.GetThum bnailImage(300, 300,
myCallback, IntPtr.Zero);
if (Request.QueryS tring["size"] == QueryStringFull Size)
myThumbnail = fullImg;
// make a memory stream to work with the image bytes
MemoryStream imageStream = new MemoryStream();
// put the image into the memory stream
myThumbnail.Sav e(imageStream, ImageFormat.Jpe g);
// make byte array the same size as the image
byte[] imageContent = new Byte[imageStream.Len gth];
// rewind the memory stream
imageStream.Pos ition = 0;
// load the byte array with the image
imageStream.Rea d(imageContent, 0,
(int)imageStrea m.Length);
//byte[] allBytes = File.ReadAllByt es(url2);
Response.Conten tType = "image/jpeg";
Response.Cache. SetCacheability (HttpCacheabili ty.Public);
Response.Buffer Output = false;
Response.Output Stream.Write(im ageContent, 0,
imageContent.Le ngth);
}
}
//e.Graphics.Draw Image(myThumbna il, 150, 75);
}
public bool ThumbnailCallba ck()
{
return false;
}
public bool IsReusable
{
get
{
return true;
}
}
}
}
Then call the control like this:
<img id="ss_img" src="PhotoDispl ay.ashx?photoid =KeyForImage&am p;size=large"
alt="My Image" width="230" />
Just for the photoid be sure and pass something in that indicates what photo
you want. If you are generating the image at runtime - perhaps you can use
more than one parameter that can indicate Width, Height, content, etc...
-Brian
"computer_g uy" <zy*******@gmai l.comwrote in message
news:11******** *************@r 34g2000hsd.goog legroups.com...
Hi Everyone,
I run into a problem. I am trying to write an aspx that can
dynamically generate an image based on some input parameters.
Things are very simple if the size of the parameters is small and I
can put them on the URL and pass them in as HTTP GET. In my image
generation script I just need to read the parameters and then pump out
the right MIME type and the right image byte stream. It is also very
easy to use:
<img source="image_g en.aspx?p1=.... "will do the trick.
However, it looks like I need to pass in more parameters than HTTP GET
can support. I am thinking about HTTP POST. I think I can still write
the image generation script the same way, but the question now is how
to call the script and display the image in my html.
<img source="image_g en.aspx" and HTTP POST to this URLHow?
Does anyone know?
Thanks,
computer_guy