This code sample shows how to create thumbnail of an image on the fly:
1) first create a folder name Image 2) add two more folder in image folder thumbnails and Sthumbnails
Sample code:
public class utility { public utility() { // // TODO: Add constructor logic here // } public static void C_Thumbnails(int size, string FilePath, string ThumbPath) { // create an image object, using the filename we just retrieved System.Drawing.Image image = System.Drawing.Image.FromFile(FilePath);
try { int thumbHeight, thumbWidth; decimal h = image.Height; decimal w = image.Width; thumbWidth = image.Width; thumbHeight = image.Height;
if (image.Height > image.Width && image.Height > size) { thumbHeight = size; decimal tWidth = (w / h) * thumbHeight; thumbWidth = Convert.ToInt32(tWidth); } else { if (image.Width > size) { thumbWidth = size; decimal tHeight = (h / w) * thumbWidth; thumbHeight = Convert.ToInt32(tHeight); } } // create the actual thumbnail image System.Drawing.Image thumbnailImage; thumbnailImage = image.GetThumbnailImage(thumbWidth, thumbHeight, null, IntPtr.Zero); image.Dispose();
// put the image into the memory stream thumbnailImage.Save(ThumbPath, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (Exception ex) { image.Dispose(); throw ex; } } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|