Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i want run ThumbnailViewer.aspx from img tag but it not correctly work
please help me.

C#
protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected string GetURL()
        {
        return"ThumbnailViewer.aspx?FilePath=" + Server.UrlEncode(@"C:\Koala_3D.jpg");
        }

XML
<form id="form1" runat="server">

   <img src='<%#GetURL() %>'   runat="server" />
   <asp:Image ID="Image1" runat="server"  ImageUrl="<%#GetURL() %>" />

   </form>


C#
public partial class ThumbnailViewer : System.Web.UI.Page
   {
       protected void Page_Load(object sender, EventArgs e)
       {
           if ((String.IsNullOrEmpty(Request.QueryString["X"])) ||
               (String.IsNullOrEmpty(Request.QueryString["Y"])) ||
               (String.IsNullOrEmpty(Request.QueryString["FilePath"])))
           {
               // There is missing data, so don't display anything.
               // Other options include choosing reasonable defaults
               // or returning an image with some static error text.
           }
           else
           {
               int x = Int32.Parse(Request.QueryString["X"]);
               int y = Int32.Parse(Request.QueryString["Y"]);
               string file = Request.QueryString["FilePath"];
               file = Server.MapPath(file);
               // Create the in-memory bitmap where you will draw the image.
               Bitmap image = new Bitmap(x, y);
               Graphics g = Graphics.FromImage(image);

               // Load the file data.
               System.Drawing.Image thumbnail =
               System.Drawing.Image.FromFile(file);

               // Draw the thumbnail.
               g.DrawImage(thumbnail, 0, 0, x, y);

               // Render the image.
               image.Save(Response.OutputStream, ImageFormat.Jpeg);
              // image.Save(Response.OutputStream, ImageFormat.Jpeg);
               g.Dispose();
               image.Dispose();
           }

       }
   }
Posted
Comments
Sandeep Mewara 3-Aug-12 15:19pm    
Explain "but it not correctly work"

1 solution

Your hard coded image is not inside your web server, and you're not even trying to map the path. You're setting the img source to be a page, which wound read the file if hte URL being passed in was viable, but it does not set the MIME type. As far as I can see, pretty much every part of this is being done wrong. I would suggest you set some break points and step through it, to see what is happening, define 'not correctly work' when you ask a question, and read up on setting the MIME type when you return an image via a page.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900