User931330785 posted
I am wanting to resize images in the background. I do this because the images we have on our site are rather large and I did not want to resize each one because eventually there will be links to the original file for downloading.
For some reason some images resize properly (http://www.ajnicholsfam.com/gallery/image.aspx?img=001.jpg) while others do not (http://www.ajnicholsfam.com/gallery/image.aspx?img=009.jpg).
I have attached the source below and from my output all my math is proper, yet for some reason asp does not seem to do it properly.
1 <%@Import Namespace="System.Drawing.Imaging" %>
2 <script language="<span" class="st">"c#" runat="server">
3
4 public bool ThumbnailCallback(){return false;}
5
6 protected void Page_Load(Object sender, EventArgs e)
7 {
8 System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
9 System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath("/images/" + Request.QueryString["img"]));
10 fullSizeImg.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
11 fullSizeImg.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
12 int width = 640;
13 int height = (fullSizeImg.Height/(fullSizeImg.Width/width));
14 if (Request.QueryString["w"] != null)
15 {
16 width = Convert.ToInt32(Request.QueryString["w"]);
17 height = Convert.ToInt32(Request.QueryString["w"]);
18 }
19
20 /*System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(width, height, dummyCallBack, IntPtr.Zero);*/
21
22 Response.Write(fullSizeImg.Height + "<br>");
23 Response.Write(fullSizeImg.Height + "/(" + fullSizeImg.Width + "/" + width + ")<br>");
24 Response.Write((fullSizeImg.Height/(fullSizeImg.Width/width)) + "<br>");
25 Response.Write(fullSizeImg.Height/(fullSizeImg.Width/width) + "<br>");
26 Response.Write(width + "<br>");
27 Response.Write(height);
28 /*fullSizeImg = thumbNailImg;*/
29
30 /*Response.ContentType = "image/Jpeg";
31 fullSizeImg.Save(Response.OutputStream, ImageFormat.Jpeg);
32 fullSizeImg.Dispose();*/
33 }
34
35 </script>