Hi,
I am trying to fix the widht and height of the image chosen in telerik RadEditior, i have tried with both Javascript and C# code saperately which i found in forums, but could not resolve.
I am using V.S 2010 and telerik product version 2009.3.1103.35.
Javascript used:
<script type="text/javascript">
function OnClientLoad(editor, args) {
editor.attachEventHandler(
"oncontrolselect", function () {
//Check if image
window.setTimeout(
function () {
var selElem = editor.getSelection().getParentElement();
alert(selElem.tagName);
if (selElem.tagName == "IMG") {
//Store current width and height
curWidth = selElem.offsetWidth;
curHeight = selElem.offsetHeight;
//Possible to resize, so attach eventhandler
selElem.onresizeend =
function (e) {
alert("I was resized");
selElem.style.width = "150";
selElem.style.height ="150";
selElem.onresizeend = null; //remove handler
//Make calculations about skaling, then re-size image
};
}
}, 0);
});
}
Code used in C#
The one which i have found in these attachements,
In page_load
{ string [] paths = new string[] { "~/Images/editor" };
RadEditor1.ImageManager.ViewPaths = paths;
RadEditor1.ImageManager.UploadPaths = paths;
RadEditor1.ImageManager.DeletePaths = paths;
RadEditor1.ImageManager.ContentProviderTypeName =
typeof(ChangeImageSizeProvider).AssemblyQualifiedName;
}
public class ChangeImageSizeProvider : Telerik.Web.UI.Widgets.FileSystemContentProvider
{
public ChangeImageSizeProvider(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(UploadedFile file, string path, string name, params string[] arguments)
{
System.Drawing.Image image = System.Drawing.Image.FromStream(file.InputStream);
string physicalPath = Context.Server.MapPath(path);
int newWidth = 100;// Fixed width
int newHeight = 100;// Fixed height
System.Drawing.Image resultImage = ResizeImage(image, new Size(newWidth, newHeight));
resultImage.Save(physicalPath + name);
string result = path + name;
return result;
}
private System.Drawing.Image ResizeImage(System.Drawing.Image sourceImage, Size newSize)
{
Bitmap bitmap = new Bitmap(newSize.Width, newSize.Height);
Graphics g = Graphics.FromImage((System.Drawing.Image)bitmap);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(sourceImage, 0, 0, newSize.Width, newSize.Height);
g.Dispose();
return (System.Drawing.Image)bitmap;
}
}
I have a save option with which i am saving
asdf.Content = this.RadEditor1.Content;
asdf.save();
Please let me know, if I need to do anything else.
Thanks
G Krishna