Dynamic Images


M

Martin Schmid

I have a aspx with the code below... I am trying to get the output from the
Click redirect to display an image that may be right-clicked to 'save as'.
The image displays as expected, but when 'saving as', it just saves a text
file of the original webform.aspx, not the binary image displayed in the
browser.

Any ideas?
Thx,
MS


(From Webform.aspx)
void IB_Click(object sender, ImageClickEventArgs e)
{
ImageButton ib=(ImageButton)sender;
string url="Result.aspx?file=" + ib.ImageUrl.ToString() + "&size=" +
DropDownList1.SelectedItem.Value;
Response.Redirect(url);
}

The result.aspx is below:
<%@ Page language="c#" AutoEventWireup="false" Codebehind="Result.aspx.cs"
Inherits="spc.Result" %>



The result.aspx.cs is thus:

public class Result : System.Web.UI.Page
{
System.Drawing.Image ResizeImage (System.Drawing.Image img, int width, int
height)
{
System.Drawing.Bitmap b;
System.Drawing.Image i;
System.Drawing.Graphics g;
b=new System.Drawing.Bitmap(width,height);
i=System.Drawing.Image.FromHbitmap(b.GetHbitmap());
g=System.Drawing.Graphics.FromImage(i);
g.DrawImage(img,0,0,width,height);
g.Dispose();
img.Dispose();
return i;
}

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string path= Request.QueryString.GetValues("file").GetValue(0).ToString();
double size =
Convert.ToDouble(Request.QueryString.GetValues("size").GetValue(0).ToString(
));
string fName = path.Substring(0,path.Length-7) + ".jpg";
System.Drawing.Image fullSizeImg;
System.Drawing.Bitmap bmp;
System.Drawing.Graphics g;
fullSizeImg=System.Drawing.Image.FromFile(Server.MapPath(fName));
Response.Clear();
Response.ContentType="image/jpeg";
bmp=new System.Drawing.Bitmap(1,1);
g=System.Drawing.Graphics.FromImage(fullSizeImg);
bmp=(System.Drawing.Bitmap)fullSizeImg;
int height = (int)(fullSizeImg.Height*size);
int width = (int)(fullSizeImg.Width*size);
bmp=(System.Drawing.Bitmap)(ResizeImage(bmp,width,height));
bmp.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
bmp.Dispose();
}
 
Ad

Advertisements


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

Top