Create Thumbnail

image_pdfimage_print
   
 

//http://activedeveloperdk.codeplex.com/
//The MIT License (MIT)
using System;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
using System.Configuration;

namespace ActiveDeveloper.Core.Utilities
{
  public sealed class GDI
  {
    /// <summary>
    /// 
    /// </summary>
    /// <param name="imagePathAndName"></param>
    /// <param name="newHeight"></param>
    /// <param name="newWidth"></param>
    /// <returns>Name of the created thumbnail. E.g: small_thumb.jpg</returns>
    public static string CreateThumbnail(string imagePathAndName, int newHeight, int newWidth )
    {
      using( Bitmap bitmap = new Bitmap( imagePathAndName ) ) {
        Image thumbnail = bitmap.GetThumbnailImage( newWidth, newHeight, null, new IntPtr() );

        FileInfo fileInfo = new FileInfo( imagePathAndName );
        string thumbnailName = ConfigurationManager.AppSettings[ "ThumbnailAbr" ] + fileInfo.Name;
        thumbnail.Save( fileInfo.Directory.ToString() + Path.DirectorySeparatorChar + thumbnailName );

        return thumbnailName;
      }
    }
  }
}

   
     


This entry was posted in File Stream. Bookmark the permalink.