My contemplations and diurnal novelties are publicized here

Archive for April 1, 2010

Thumbnail creation using C#


You can simply create a thumbnail using following code:-

 

private void CreateThumbNail(string fileName)

        {

            // create an image object for source file

            System.Drawing.Image image = System.Drawing.Image.FromFile(fileName);

            // get another image instance using GetThumbnailImage method  NOTE:- A CALLBACK DELEGATE IS NEED HERE

            System.Drawing.Image thumbNail = image.GetThumbnailImage(100, 100, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);

            // Save the thumbnail to another directory with same name

            fileName = fileName.Replace("\\gallery500\\", "\\thumbnail\\");

            // Create a file stream to be passed to thumbnail save method

            System.IO.FileStream fs = new FileStream(fileName, FileMode.Create);

            // Save the thumbnail

            thumbNail.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);

            // close file stream

            fs.Close();

        }

        public bool ThumbnailCallback()

        {

            return true;

        }

Query to extract extension of files


Do you want to extact your file extension. Do it using SQL! As follow:-

 

SELECT Collection.Item_No,

‘~/ThumbNail/’ + substring(Imagefile,0,CHARINDEX(‘.’,Imagefile,0))  + ‘_thumb’ + substring(Imagefile,CHARINDEX(‘.’,Imagefile,0),len(Imagefile))  ThumbNail,

‘this.src=”’ +  ‘Gallery/’ + ImageFile + ”” MouseOver,

‘this.src=”’ +  ‘ThumbNail/’ + substring(Imagefile,0,CHARINDEX(‘.’,Imagefile,0))  + ‘_thumb’ +

substring(Imagefile,CHARINDEX(‘.’,Imagefile,0),len(Imagefile)) + ”” MouseOut,

Collection.Title, Artist.[Artist Name] AS Artist, Category.Name AS Category, Media.Media, Surface.Surface_name as Surface, styles.style_name as Style FROM Collection INNER JOIN Artist ON Collection.Artist = Artist.ID INNER JOIN Category ON Collection.cat_id = Category.ID INNER JOIN Media ON Collection.Media = Media.ID INNER JOIN Surface ON Collection.Surface = Surface.ID INNER JOIN styles ON Collection.style = styles.ID

 

 

%d bloggers like this: