Thursday, September 14, 2017

Resizing image using asp.net c#

            #region "Image Resize to 250* 250"
                try
                {
                    // Get the path of the original Image
                    string OriginalImageUrlPath="~/Testimage/TestImage.jpg"
                    string displayedImg = Server.MapPath(OriginalImageUrlPath);
                    FileInfo fi = new FileInfo(displayedImg);
                     //fi.Name="TestImage.jpg";
                    // Get the path of the Thumb folder
                    string ThumbnailImagepath = (@"~/Testimage/Thumbnail" + "/") + fi.Name;
                    string displayedImgThumb = Server.MapPath(ThumbnailImagepath );

                    // Get the original image file name
                    string imgFileName = System.IO.Path.GetFileName(displayedImg);
                    //imgFileName="TestImage.jpg";
                    // Load original image
                    System.Drawing.Image myimg = System.Drawing.Image.FromFile(displayedImg);

                    // Get the thumbnail 250X 250px
                    myimg = myimg.GetThumbnailImage(250, 250, null, IntPtr.Zero);

                    // Save the new thumbnail image
                    myimg.Save(displayedImgThumb, myimg.RawFormat);

                    Console.WriteLine("Success");
                }
                catch(Exception ex)
                {
                     Console.WriteLine("Fail");
                }
                #endregion

No comments:

Change default Port on Next.js app

 If any other app or process is running on port 3000 , you will get this error in your terminal Port 3000 is already in use. error Command f...