This is a migrated thread and some comments may be shown as answers.

resize image

3 Answers 104 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
WebGeek
Top achievements
Rank 1
WebGeek asked on 11 Feb 2009, 05:21 AM
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()));  
 
thumbnail.Save(thumbnailFileName);  
 
}  
 

3 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 11 Feb 2009, 04:26 PM
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.
0
-DJ-
Top achievements
Rank 1
answered on 17 Feb 2009, 05:43 PM
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.

Regards,
-DJ-






0
Atanas Korchev
Telerik team
answered on 18 Feb 2009, 12:02 PM
Hello -DJ-,

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

Regards,
Albert
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.
Tags
Upload (Obsolete)
Asked by
WebGeek
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
-DJ-
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or