Dimensions of uploaded image files

Last post 09-03-2009, 6:12 AM by jgra. 2 replies.
Sort Posts: Previous Next
  •  09-02-2009, 5:08 PM 55321

    Dimensions of uploaded image files

    Hi
     
    I need to get the dimensions of image files uploaded via the ajaxuploader.
     
    Is there any class that will help me do that?
     
    JG
     
     
  •  09-02-2009, 8:39 PM 55325 in reply to 55321

    Re: Dimensions of uploaded image files

    JG,
     
    Please check this code :
     
    1. <%@ Page Language="C#" Title="First sample" %>  
    2. <%@ Import Namespace="CuteWebUI" %>  
    3. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">  
    5. <script runat="server">  
    6.     void InsertMsg(string msg)   
    7.     {   
    8.         ListBoxEvents.Items.Insert(0, msg);   
    9.         ListBoxEvents.SelectedIndex = 0;   
    10.     }   
    11.     protected void UploadAttachments1_FileUploaded(object sender, UploaderEventArgs args)   
    12.     {   
    13.         //must copy the stream to MemoryStream, otherwise the stream may be locked by Image object   
    14.         byte[] data = new byte[args.FileSize];   
    15.         using (Stream stream = args.OpenStream())   
    16.         {   
    17.             stream.Read(data, 0, args.FileSize);   
    18.         }   
    19.         System.Drawing.Image img=null;   
    20.         try   
    21.         {   
    22.             img = System.Drawing.Image.FromStream(new MemoryStream(data));   
    23.         }   
    24.         catch   
    25.         {   
    26.         }   
    27.         if (img == null)   
    28.         {   
    29.             InsertMsg("What you uploaded is not a image");   
    30.         }   
    31.         else   
    32.         {   
    33.             InsertMsg("You have uploaded a image : " + img.Width + "x" + img.Height);   
    34.         }   
    35.     }   
    36. </script>  
    37.   
    38. <html xmlns="http://www.w3.org/1999/xhtml">  
    39. <head id="Head1" runat="server">  
    40. </head>  
    41. <body>  
    42.     <form id="Form1" runat="server">  
    43.         <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1" OnFileUploaded="UploadAttachments1_FileUploaded">  
    44.         </CuteWebUI:UploadAttachments>  
    45.         <br />  
    46.         <div>  
    47.             Server Trace:   
    48.             <br />  
    49.             <asp:ListBox runat="server" ID="ListBoxEvents" Width="800"></asp:ListBox>  
    50.         </div>  
    51.     </form>  
    52.   
    53. </body>  
    54. </html>  

    Regards,
    Terry
  •  09-03-2009, 6:12 AM 55345 in reply to 55325

    Re: Dimensions of uploaded image files

    That'll work!
     
    Thanks
     
    JG
View as RSS news feed in XML