Hello,
I'm trying to automatically resize images when they're being uploaded. After reading on the forums for a while, I found out I can use a FileSystemContentProvider for this.
Here's what I've come up with:
public class TextEditor : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
radEditor.ImageManager.ContentProviderTypeName = typeof(MyResizer).AssemblyQualifiedName;
radEditor.ImageManager.ViewPaths = new[] { "~/Images" };
radEditor.ImageManager.UploadPaths = new[] { "~/Images" };
radEditor.ImageManager.DeletePaths = new[] { "~/Images" };
}
}
public class MyResizer : FileSystemContentProvider
{
public MyResizer(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl,
string selectedItemTag) : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
{
}
public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
{
string result = base.StoreFile(file, path, name, arguments);
using (System.Drawing.Image originalImage = Bitmap.FromStream(file.InputStream))
{
int originalWidth = originalImage.Width;
int originalHeight = originalImage.Height;
int newWidth = 500;
int newHeight = originalHeight / originalWidth * newWidth;
System.Drawing.Image resizedImage = ResizeImage(originalImage, newWidth, newHeight);
string fileName = Path.Combine(path, name);
resizedImage.Save(Context.Server.MapPath(fileName));
}
return result;
}
private Image ResizeImage(Image originalImage, int newWidth, int newHeight)
{
// Resize Image
}
}
This works fine, but as you can see the new width of the image (500) is hard coded. How can I turn this into a parameter?
We access the page with the Editor on it like this: /TextEditor.aspx?textid=1&
ImageWidth=500
How can we pass the ImageWidth parameter in the querystring to our implementation of the FileSystemContentProvider?
Regards,
Kristof