Click here to Skip to main content
16,017,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a folder of images in my project now i need to have a second folder where i will store images as thumbnails so that they appear in small sizes. How can i save them in that folder?
Posted
Comments
F-ES Sitecore 7-Sep-15 6:48am    
Have you googled "create image thumbnail c#" and gone through some tutorials?

I'd create a subdirectory called "Thumbs" and store the thumb image in that under exactly the same name as the full image.
Then I use this code:
C#
/// <summary>
/// Create a thumbnail image.
/// </summary>
/// <param name="path">path to full size image</param>
/// <param name="width">Width of thumbnail</param>
/// <param name="height">Height of thumbnail</param>
public static Image GetThumbnailImage(string path, int width, int height)
    {
    using (Image image = Image.FromFile(path))
        {
        Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
        return image.GetThumbnailImage(width, height, myCallback, IntPtr.Zero);
        }
    }
/// <summary>
/// This is not used in GDI+ 1.0, but must be supplied to some GDI calls.
/// E.g. Image.GetThumbnailImage
/// </summary>
/// <returns>false always</returns>
private static bool ThumbnailCallback()
    {
    return false;
    }

All you need then is to call Image.Save to save the thumbnail.
 
Share this answer
 
Comments
Arasappan 7-Sep-15 6:55am    
fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900