By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Dynamic Images

P: n/a
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("si ze").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.M apPath(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.Imag ing.ImageFormat.Jpeg);
g.Dispose();
bmp.Dispose();
}

--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.