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

Fit image size to Image Editor size

3 Answers 697 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 29 Oct 2018, 03:36 PM

I want to display an image editor withuot tools. (I need only the ability to control the brightness and contrast, what I can do programmatically).

I want the image will be displayed fully in the image editor, without scrolling.

How can I do that?

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 31 Oct 2018, 12:35 PM
Hello David,

To use the image editor without the tools use only RadImageEditor, instead of RadImageEditorUI.  

To control the brightness and contrast manually, you can use the ImageCommands.Contrast command. Here is an example in code:
private void Button_Click(object sender, RoutedEventArgs e)
{
    double contrast = 0.7; // between 0 and 2
    double brightness = 0.4; // between -1 and 1
    var context = new ContrastCommandContext(brightness, contrast);
    this.imageEditor.ExecuteCommand(ImageCommands.Contrast, context);
}
Check also the attached project.

To display the image fully without scrolling, you can set the ScaleFactor of the RadImageEditor control to 0. This will make the control to enter auto fit mode, which means that the picture will be zoomed out so that it is full displayed.

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
David
Top achievements
Rank 1
answered on 01 Nov 2018, 10:55 AM

Thank you.

It almost what I want: I want the image to be exactly in the same size as the image editor, and let it stretch if needed.

Is it possible?

0
Martin Ivanov
Telerik team
answered on 02 Nov 2018, 02:18 PM
Hello David,

There is not such functionality in the control, but you should be able to achieve your requirement by playing with the ScaleFactor property of the control. So, you can zoom the image so that it fits into the RadImageEditor's size.

An alternative approach would be to manually set the Width and Height of the Grid panel holding the image, when you open a new file. For example:
private void ImageEditor_CommandExecuted(object sender, Telerik.Windows.Media.Imaging.ImageEditorCommands.ImageCommandExecutedEventArgs e)
{           
    if (e.Command is OpenImageCommand)
    {
        Grid imageView = this.imageEditor.ChildrenOfType<Grid>().FirstOrDefault(x => x.Name == "ImageView");
        imageView.Width = this.imageEditor.ActualWidth;
        imageView.Height = this.imageEditor.ActualHeight;
    }
}

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ImageEditor
Asked by
David
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
David
Top achievements
Rank 1
Share this question
or