Set Height and Width to any Images in asp
string filename1 = "", filename2 = "";string str1, str2;
if (FilePhoto1.HasFile)
{
string extension = Path.GetExtension(FilePhoto1.FileName);
Stream strm = FilePhoto1.PostedFile.InputStream;
using (var image = System.Drawing.Image.FromStream(strm))
{
String Size = image.Size.ToString();
int newWidth = 200; // New Width of Image in Pixel
int newHeight = 200; // 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);
filename1 = Path.GetFileName(FilePhoto1.FileName);
Random rd = new Random();
int s = rd.Next();
str2 = s + FilePhoto1.PostedFile.FileName;
string targetPath = Server.MapPath("~/FolderName/") + str2;
thumbImg.Save(targetPath, image.RawFormat);
// FilePhoto1.PostedFile.SaveAs(Server.MapPath("~/FolderName/" + thumbImg));
// cmd.Parameters.AddWithValue("@Photo1", str2);
}
}
No comments:
Post a Comment