Dear Team,
we have trying to store image to database with resize & compress the image but image store without extetion refer the below code which written by me
below code is successfully store image to folder
// Check file exist or not
if (FileUpload1.PostedFile != null)
{
// Check the extension of image
string extension = Path.GetExtension(FileUpload1.FileName);
if (extension.ToLower() == ".png" || extension.ToLower() == ".jpg")
{
Stream strm = FileUpload1.PostedFile.InputStream;
using (var image = System.Drawing.Image.FromStream(strm))
{
// Print Original Size of file (Height or Width)
Label1.Text = image.Size.ToString();
int newWidth = 100; // New Width of Image in Pixel
int newHeight = 100; // New Height of Image in Pixel
var thumbImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imgRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imgRectangle);
// Save the file
string targetPath = Server.MapPath(@"~\Images\") + FileUpload1.FileName;
thumbImg.Save(targetPath, image.RawFormat);
// Print new Size of file (height or Width)
Label2.Text = thumbImg.Size.ToString();
//Show Image
Image1.ImageUrl = @"~\Images\" + FileUpload1.FileName;
}
}
}
Thanks in advance