I want to insert an image in the RadRichtextbox by giving absolute url like http://xxx/image1.jpg (similar to insert image functionality in the AjaxRadEditor) . Is there any option for this?
Thanks,
Deepthi P
3 Answers, 1 is accepted
To your question, ImageInline does support creation of images from an absolute URI. The site in which the image is hosted, however, has to allow that in its cross-domain policy file. A simple example (for a site that has a permissive cross-domain policy) is provided below:
string
url =
"http://romeo.roy.free.fr/photos/Maroc1/IMG_0930-1600.jpg"
;
ImageInline imageInline =
new
ImageInline()
{
UriSource =
new
Uri(url, UriKind.Absolute),
Width = 150,
Height = 150,
};
this
.radRichTextBox1.InsertInline(imageInline);
In case the site does not have a permissive policy, you can try:
Image image =
new
Image()
{
Source =
new
BitmapImage(newUri(url, UriKind.Absolute)),
Width = 150,
Height = 150,
};
InlineUIContainer imageContainer =
new
InlineUIContainer(image, newSize(150, 150));
this
.radRichTextBox1.InsertInline(imageContainer);
You can read more about Silverlights' security policy system here.
Best wishes,Iva
the Telerik team
The approaches shown below illustrate the inserting of images from an absolute web Uri.
In order to be able to retrieve an image from the local machine, a slightly different approach should be used. First of all, the application must require elevated trust when running outside of the browser (see attached screenshot).
Then, you could access a file using an absolute URI such as "C:/Users/itoteva.TELERIK/Pictures/tick.png". However, ImageInline does not handle automatically URIs in this format, so you should obtain the image yourself and use it to instantiate an ImageInline. This can be done like this:
BitmapImage bitmapImage =
new
BitmapImage(
new
Uri(url, UriKind.Absolute));
bitmapImage.CreateOptions = BitmapCreateOptions.None;
bitmapImage.ImageOpened += (s, a) =>
{
WriteableBitmap writableBitmap =
new
WriteableBitmap((BitmapImage)s);
ImageInline image =
new
ImageInline(writableBitmap);
this
.radRichTextBox.InsertInline(image);
};
I hope this helps.
Regards,
Iva Toteva
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>