RADUpload auto resize width only

Thread is closed for posting
2 posts, 0 answers
  1. sammy ymmas
    sammy ymmas avatar
    7 posts
    Member since:
    Jul 2009

    Posted 08 Jun 2010 Link to this post

    Hi!
    I would like to resize files that are being uploaded automatically. But I only want to resize the width. Regarding the height of the file, this should auto adjust it self. Forexample; If I'm uploading a file that is 1000 px in width and 2000px in height and then resize it to 500px in width, then I want the height to be auto resized to 1000px. In other words the height and width has to be proportional.

    This is the code that I'm using right now.

      int width = 500;
      int height = 500;
      using (System.Drawing.Image thumbnail = originalImage.GetThumbnailImage(width, height, thumbnailImageAbortDelegate, IntPtr.Zero))
      {
          string thumbnailFileName = Path.Combine(target, string.Format("{0}_BigPicture{1}", file.GetNameWithoutExtension(), file.GetExtension()));
          thumbnail.Save(thumbnailFileName);

    The problem with this is that is has to take both the height and the width. I cannot leave out the height parameter.

    P.S. My DLL version is 2009.3.1208.35 > Telerik.Web.UI.dll (ASP.NET Ajax)

    So I hope someone can help.

    Thanks
  2. sammy ymmas
    sammy ymmas avatar
    7 posts
    Member since:
    Jul 2009

    Posted 15 Jun 2010 Link to this post

    Hi guys!
    I finally found a solution through help from forums.asp.net

    The code below is made under the assumption that the width of the image will always be resized to 500px and the height will be adjusted proportionally.

    protected void Button1_Click(object sender, EventArgs e)   
    {   
        string target = Server.MapPath("~/Images");   
        System.Drawing.Image.GetThumbnailImageAbort thumbnailImageAbortDelegate = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);   
       
        foreach (UploadedFile file in RadUpload1.UploadedFiles)   
        {   
            using (Bitmap originalImage = new Bitmap(file.InputStream))   
            {   
                decimal w1, h1, width2;   
                w1 = originalImage.Width;   
                h1 = originalImage.Height;   
                width2 = calculations(w1, h1);   
       
                int height = Convert.ToInt32(width2);   
                int width = 500;   
                using (System.Drawing.Image thumbnail = originalImage.GetThumbnailImage(width, height, thumbnailImageAbortDelegate, IntPtr.Zero))   
                {   
                    string thumbnailFileName =  Path.Combine(target, string.Format("{0}_thumb{1}", file.GetNameWithoutExtension(), file.GetExtension()));   
                    thumbnail.Save(thumbnailFileName);   
                }   
            }   
        }   
    }   
       
    public bool ThumbnailCallback()   
    {   
        return false;   
    }   
       
       
    public decimal calculations(decimal w1, decimal h1)   
    {    
        decimal height = 0;   
        decimal ratio = 0;   
        const int myWidth = 500;   
           
          
        if (myWidth < w1)   
        {   
            ratio = w1 / myWidth;   
            height = h1 / ratio;   
       
            return height;   
        }   
       
         if (w1 < myWidth)   
        {   
            ratio = myWidth / w1;   
            height = h1 * ratio;   
            return height;   
        }   
       
        return height;   
    }   

    Well that's it. Now the height will always resize itself proportionally. 

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top