Upload and Resize Image in the Asp.net Using C#.Net .
const int IMAGE_WIDTH = 550;
const int IMAGE_HEIGHT = 176;
(We can change the Width and Height)
public void UploadImageAd()
{
try
{
string strFolderName = "Banner_Images";
string strFolderPath = Server.MapPath(strFolderName);
//string strSavePath = "~/" + strFolderName + "/";
string strFileName = string.Empty;
string strSaveFilePath=strFolderPath;
if (!Directory.Exists(strFolderPath))
{
Directory.CreateDirectory(strFolderPath);
}
if (FileUploadImage.HasFile)
{
strFileName = FileUploadImage.FileName;
strSaveFilePath += "/" + strFileName;
string strRealImagePath = Server.MapPath("RealImage");
strRealImagePath += "/" + strFileName;
FileUploadImage.SaveAs(strRealImagePath);
//Resize and Save Image
string strImageUrl = strRealImagePath;
ResizeImage(strImageUrl,strSaveFilePath);
//RealImage
//
m_strImagePath = "~/" + strFolderName + "/" + strFileName;
}
}
catch (Exception objException)
{
throw new Exception(objException.Message.ToString());
}
}
public void ResizeImage(string strImageUrl,string strSaveFilePath)
{
try
{
System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(strImageUrl);
System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(IMAGE_WIDTH, IMAGE_HEIGHT, dummyCallBack, IntPtr.Zero);
//Save the thumbnail in Png format. You may change it to a diff format with the ImageFormat property
thumbNailImg.Save(strSaveFilePath, ImageFormat.Png);
thumbNailImg.Dispose();
}
catch (Exception ObjException)
{
throw new Exception(ObjException.Message.ToString());
}
}
tag-Upload and Resize Image in the Asp.net Using C#.Net .
Resize image ,Upload Image in VS 2005
Articles
- Articles(C#.NET) (3)
- ASP.NET (6)
- Asp.Net(Email) (1)
- Asp.net(Image) (2)
- Asp.Net(Web.Config) (2)
- C#.NET (5)
- C#.NET Threading (3)
- C#.NET(ASP.NET) (4)
- Comments in PHP (1)
- Encryption In PHP (1)
- iPhone (Articles) (1)
- JavaScript (1)
- Json with PHP (1)
- LINQ (1)
- PHP (2)
- PHP Constant (1)
- PHP Operators (1)
- PHP Print Command (1)
- PHP Tutorial (2)
- Strings In PHP (1)
- Variable Declaration In PHP (1)
- WPF (1)
- XAML (2)
About Me
Help Link
Followers
Posted by
Sreejith A.K
Wednesday, September 29, 2010
Labels:
Asp.net(Image)
Subscribe to:
Post Comments (Atom)