This is a migrated thread and some comments may be shown as answers.

Inserting an image in the RadRichtextbox

3 Answers 284 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Deepthi
Top achievements
Rank 1
Deepthi asked on 07 Jan 2011, 10:28 AM
Hi ,
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

Sort by
0
Iva Toteva
Telerik team
answered on 10 Jan 2011, 03:31 PM
Hello Deepthi,

 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:

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
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Pablo
Top achievements
Rank 1
answered on 27 Aug 2013, 12:21 PM
I'm building an OOB Silverlight app and I need to insert local file images programmatically but I the code sample you posted doesn't work, please help.
0
Iva Toteva
Telerik team
answered on 28 Aug 2013, 12:50 PM
Hi Pablo,

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
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
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 >>
Tags
RichTextBox
Asked by
Deepthi
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Pablo
Top achievements
Rank 1
Share this question
or