Hi,
I need to run exactly this code in an asp.net file when someone uploads an
image, but i dont know C# and im having real issues converting it.
If anyone can, could you convert it to VB.net for me to use ? Loads of karma
in it for you :)
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<script Language="C#" runat="server">
protected Size ThumbNailSize = new Size(75,75);
protected string ThumbNailName = "_thumbnail";
private void Page_Load(object sender, System.EventArgs e)
{
if (RequestObject("generate") == "1")
{
GenerateThumbNailImagesForFolder(RequestObject("im gfolder"));
}
}
public void GenerateThumbNailImagesForFolder(string FolderName)
{
string sPhysicalPath="";
string sFileName="";
string sThumbName="";
sPhysicalPath = Server.MapPath(FolderName);
DirectoryInfo oDir = new DirectoryInfo(sPhysicalPath);
try
{
FileInfo[] oDeleteFiles = oDir.GetFiles();
foreach (FileInfo oFile in oDeleteFiles)
{
sFileName = oFile.Name.ToLower();
if (sFileName.IndexOf("thumbnail") > 0) {
oFile.Delete(); }
}
FileInfo[] oFiles = oDir.GetFiles();
foreach (FileInfo oFile in oFiles)
{
sFileName = oFile.Name.ToLower();
sThumbName = sFileName.Replace(".",this.ThumbNailName
+ ".");
if (sFileName.IndexOf(".gif") > 0)
{
this.GenerateThumbNail(sPhysicalPath,sFileName,sTh umbName,ImageFormat.Gif);
}
if (sFileName.IndexOf(".jpg") > 0)
{
this.GenerateThumbNail(sPhysicalPath,sFileName,sTh umbName,ImageFormat.Jpeg);
}
if (sFileName.IndexOf(".bmp") > 0)
{
this.GenerateThumbNail(sPhysicalPath,sFileName,sTh umbName,ImageFormat.Bmp);
}
}
}
catch (Exception) { }
}
public void GenerateThumbNail(string sPhysicalPath,string
sOrgFileName,string sThumbNailFileName,ImageFormat oFormat)
{
try
{
System.Drawing.Image oImg =
System.Drawing.Image.FromFile(sPhysicalPath + @"\" + sOrgFileName);
System.Drawing.Image oThumbNail = new
Bitmap(this.ThumbNailSize.Width, this.ThumbNailSize.Height,
oImg.PixelFormat);
Graphics oGraphic = Graphics.FromImage(oThumbNail);
oGraphic.CompositingQuality =
CompositingQuality.HighQuality ;
oGraphic.SmoothingMode = SmoothingMode.HighQuality ;
oGraphic.InterpolationMode =
InterpolationMode.HighQualityBicubic ;
Rectangle oRectangle = new Rectangle(0, 0,
this.ThumbNailSize.Width, this.ThumbNailSize.Height);
oGraphic.DrawImage(oImg, oRectangle);
oThumbNail.Save(sPhysicalPath + @"\" +
sThumbNailFileName,oFormat);
oImg.Dispose();
}
catch (Exception) { }
}
</script>