validate the size of a jpg image in pixels.

Thread is closed for posting
3 posts, 1 answers
  1. ALBERT
    ALBERT avatar
    38 posts
    Member since:
    Dec 2010

    Posted 16 May 2012 Link to this post

    the only thing I could validate the size of the option MaxFileSize. I have to validate to upload a photo that is 96x96 pixels. How do I can do?.

    Thanks for your help
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 May 2012 Link to this post

    Hello Albert,

    Try the following code to achieve your scenario.
    aspx:
    <telerik:RadUpload ID="RadUpload1" runat="server" AllowedFileExtensions=".jpg"></telerik:RadUpload>
    <asp:Button ID="Button1" runat="server" Text="j" onclick="Button1_Click" />
    C#:
    protected void Button1_Click(object sender, EventArgs e)
    {
     if (RadUpload1.UploadedFiles.Count > 0)
     {
       foreach (UploadedFile theFile in RadUpload1.UploadedFiles)
       {
         System.Drawing.Image myImage = System.Drawing.Image.FromStream(theFile.InputStream);
         if (myImage.Width > 96 || myImage.Height > 96)
         {
             Response.Write("<script>alert('Large image');</script>");
         }
       }
     }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ALBERT
    ALBERT avatar
    38 posts
    Member since:
    Dec 2010

    Posted 17 May 2012 Link to this post

    perfect. Thank you very much for your help
Back to Top