resize image

Thread is closed for posting
4 posts, 0 answers
  1. WebGeek
    WebGeek avatar
    39 posts
    Member since:
    Dec 2006

    Posted 10 Feb 2009 Link to this post

    Based on your help file code, I would like to figure out how to create two thumbnails (one <=100 pixels wide and another <=700 pixels wide) and maintain the aspect ratio (constraint). 

    string target = Server.MapPath("~/Images/Logos/");  
    Image.GetThumbnailImageAbort thumbnailImageAbortDelegate =  
    new Image.GetThumbnailImageAbort(ThumbnailCallback);  
    foreach (UploadedFile file in RadUpload1.UploadedFiles)  
    file.SaveAs(Path.Combine(target, file.GetName()));  
    using (Bitmap originalImage = new Bitmap(file.InputStream))  
    //You can implement additional logic to compute  
    // the width / height according your requirements  
    int width = originalImage.Width / 2;  
    int height = originalImage.Height / 2;  
    using (Image thumbnail =  
    originalImage.GetThumbnailImage(width, height, thumbnailImageAbortDelegate, IntPtr.Zero))  
    string thumbnailFileName = Path.Combine(target,  
    string.Format("{0}_thumb{1}", file.GetNameWithoutExtension(), file.GetExtension()));  
  2. Genady Sergeev
    Genady Sergeev avatar
    1595 posts

    Posted 11 Feb 2009 Link to this post

    Hello James,

    Thank your for contacting us.

    Unfortunately, it happened the method that Microsoft offers for thumbnails ( GetThumbNailImage ) ,
    is not working correctly for pictures which size is bigger than 120x120 pixels ( explanation on MSDN ).
    If you need to create bigger thumbnails, it might be better to use resizing.

    For your convenience, i have attached a demo with the correct methods to use for both small and big thumbnails.

    Sincerely yours,
    Genady Sergeev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft R3 2016 release webinar banner
  4. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 17 Feb 2009 Link to this post

    Hi Genady,

    I was trying to translate the code to vb, and it almost works.

        public bool ThumbnailCallback()
            return false;

    translates to:

     Public Function ThumbnailCallback() As Boolean
         Return False
     End Function

    but I always get an error when calling it:
    Dim thumbnailImageAbortDelegate As New System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback)

    Compiler Error Message: BC32008: Delegate 'System.Drawing.Image.GetThumbnailImageAbort' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor.


  5. Atanas Korchev
    Atanas Korchev avatar
    8462 posts

    Posted 18 Feb 2009 Link to this post

    Hello -DJ-,

    As suggested by the exception you need to use the AddressOf operator when passing the method.

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top