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

Access to RadImageEditor tools

8 Answers 159 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Davide
Top achievements
Rank 1
Davide asked on 19 May 2014, 03:24 PM
Hi, 

is there a way to access to RadImageEditor tools from code behind ... 

My intent is to change some images values such as brightness, contrast and sharpness from code and not from the UI.

Thx in advance

Davide

8 Answers, 1 is accepted

Sort by
0
Maurício
Top achievements
Rank 1
answered on 19 May 2014, 08:12 PM
Hi Davide,

I think I did something like that.. but I am not sure if it's what you need, or if it's the best way to do it:

public RadBitmap ChangeContrast(RadBitmap sourceBitmap, double brightness, double contrast)
      {
          var contrastCommand = new ContrastCommand();
     
          var contrastCommandContext = new ContrastCommandContext(brightness, contrast);
 
          return contrastCommand.Execute(sourceBitmap, contrastCommandContext);
      }

The start values for the brightness and contrast are 0 and 1:
ImageEditor.Image = ChangedContrast(ImageEditor.Image, 0, 1.0);
0
Davide
Top achievements
Rank 1
answered on 20 May 2014, 12:21 PM
Hi Mauricio ....

thx for the help. I think this is the correct way to proceed but i'm having some problems. The fact is that i want control the contrast, brightness and sharpness from three diffrent sliders and using your code i get an out of memory exception after i moved the slider for a couple of seconds. Is there a different and lighter way to apply the changes to the image?

Thx again

Davide
0
Maurício
Top achievements
Rank 1
answered on 20 May 2014, 02:16 PM
Everytime you execute the constrast command a new RadBitmap is created, thats the reason for the memory leak.
Seems that the command to apply the effect is used only after you have clicked on OK, before that, the effect is only applied to a preview control, that's why there's no memory exception while you use the built in effects.

Anyway, I don't think you can apply sharpness while you're also changing the contrast/brightness... Because you would need to apply contrast/brightness first and then the sharpness directly to the element, and you can't do that...  :(

Let's wait for telerik's answer
0
Davide
Top achievements
Rank 1
answered on 20 May 2014, 02:23 PM
What I do is:
save the starting image in a RadBitmapImage (sourceImg)

contrastCommandContext = new ContrastCommandContext(BrightnessValue, ContrastValue);
imageCopy = contrastCommand.Execute(sourceImg, contrastCommandContext);
sharpCommandContext = new SharpenCommandContext(Sharpness / 100, sourceImageSize);
ImageEditor.Image = sharpCommand.Execute(imageCopy, sharpCommandContext);

As you can see i first apply the contrart tool and from that image apply the sharp tool. I have to do this because otherwise I am not able to restore the original image.
Hope to find a solution to this.
I think that the problem is in the fact that I have to build a new Context every time but perhaps I'm wrong.
I hope to have a reply from telerik.



0
Maurício
Top achievements
Rank 1
answered on 20 May 2014, 04:22 PM
Davide check the attachment, I had to rename to .PNG to upload, but it's a .ZIP.
Just rename the extension, extract and reference the following DLLs:
Telerik.Windows.Controls
Telerik.Windows.Controls.ImageEditor

Ofcourse it's just a secondary solution, if you want a proper solution I think you should wait for telerik's answer.
0
Alex
Telerik team
answered on 22 May 2014, 02:35 PM
Hi Davide and Mauricio,

Mauricio - you are quite correct. Creating a custom tool that shows only a preview of the result using SharpenEffect and ContrastAdjustEffect and then creating the new RadBitmap when the tool is applied is indeed the recommended approach in such scenario.
Mauricio, we have added some points in your account as a token of gratitude for your effort.

Regards,
Alex
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Davide
Top achievements
Rank 1
answered on 17 Jun 2014, 10:14 AM
Hi, I added the RadImageEditor inside a scrollviewer because i want to zoom in the image. The strange behaviour I registered is that if I change the brightness of the image or one of the other values the application slow down... The zooming is no more fluid as before the editor change. Is there something I have to change or set to have it fluid? or do I have to change approach?

Xaml code:

<ScrollViewer Name="scrollViewer" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden" Background="Orange"  >
<Grid Name="grid" Background="Black" RenderTransformOrigin="0.5,0.5">
<Grid.LayoutTransform>
<TransformGroup>
<ScaleTransform x:Name="scaleTransform"/>
</TransformGroup>
</Grid.LayoutTransform>
<Viewbox x:Name="ImageViewBox" >
<ContentPresenter x:Name="ImageContent" >
<ContentPresenter.Content>
<telerik:RadImageEditor x:Name="MainImage" />
</ContentPresenter.Content>
</ContentPresenter>
</Viewbox>
<Rectangle x:Name="ctlSelRect" Width="100" Height="100" Visibility="Hidden" />
</Grid>
</ScrollViewer>
0
Todor
Telerik team
answered on 20 Jun 2014, 10:34 AM
Hello Davide,

I tried to reproduce the problem in several ways with different images and tools, but to no avail.

However, you can use the RadImageEditor's ScaleFactor property to zoom in/out the loaded image as well. If it is not an option for you and the problem still exists, please open a support ticket and send us a project which illustrates the described behavior in your previous post to us.

Looking forward to your answer. 

Regards,
Todor
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
ImageEditor
Asked by
Davide
Top achievements
Rank 1
Answers by
Maurício
Top achievements
Rank 1
Davide
Top achievements
Rank 1
Alex
Telerik team
Todor
Telerik team
Share this question
or