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

Inserting image and text from the code behind

1 Answer 385 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
chintan
Top achievements
Rank 1
chintan asked on 26 May 2015, 10:42 PM

Hi,

 

I would like to insert an image and text from the code behind once user has uploaded a photo with ability to re-position both (inserted image and text).

 

Currently I have followed this Demo to achieve uploaded image and showing into rad image editor correctly but same time i would like to insert an overlay image (e.g. water mark/company logo) and some text before showing it into rad image editor from the code behind (or may be from the client side - if possible).

 

Also both (inserted image and text) should be allowed to re-position once it is shown in rad image editor.

 

Any help would be really appreciated.

 

Regards,

Chintan

 

 

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 27 May 2015, 03:09 PM
Hi Chintan,

You can insert text and image to the uploaded image by using the EditableImage's InsertImage() and AddText() methods:
protected void RadImageEditor1_ImageLoading(object sender, ImageEditorLoadingEventArgs args)
{
    //Handle Uploaded images
    if (!Object.Equals(Context.Cache.Get(Session.SessionID + "UploadedFile"), null))
    {
        using (EditableImage image = new EditableImage((MemoryStream)Context.Cache.Remove(Session.SessionID + "UploadedFile")))
        {
            args.Image = image.Clone();
             
            //insert image
            System.Drawing.Image imageToInsert = System.Drawing.Image.FromFile(Server.MapPath("~/images/waterMark.png"));
            System.Drawing.Point imageCoords = new System.Drawing.Point(0,0);
            args.Image.InsertImage(imageCoords, imageToInsert);
 
            //insert text
            System.Drawing.Point textCoords = new System.Drawing.Point(150,150);
            ImageText textToInsert = new ImageText();
            textToInsert.Color = "#ff0000";
            textToInsert.Size = 32;
            textToInsert.Value = "Inserted text";
            args.Image.AddText(textCoords, textToInsert);
 
            args.Cancel = true;
        }
    }
}

Unfortunately, there is no way to allow the user to modify the inserted text/images when they are applied from the server so you can consider using the corresponding client-side methods for inserting images/text.

Regards,
Vessy
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ImageEditor
Asked by
chintan
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or