Access to RadImageEditor tools

9 posts, 0 answers
  1. Davide
    Davide avatar
    17 posts
    Member since:
    Mar 2013

    Posted 19 May 2014 Link to this post

    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
  2. Maurício
    Maurício avatar
    41 posts
    Member since:
    Jan 2011

    Posted 19 May 2014 in reply to Davide Link to this post

    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);
  3. UI for WPF is Visual Studio 2017 Ready
  4. Davide
    Davide avatar
    17 posts
    Member since:
    Mar 2013

    Posted 20 May 2014 in reply to Maurício Link to this post

    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
  5. Maurício
    Maurício avatar
    41 posts
    Member since:
    Jan 2011

    Posted 20 May 2014 in reply to Davide Link to this post

    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
  6. Davide
    Davide avatar
    17 posts
    Member since:
    Mar 2013

    Posted 20 May 2014 in reply to Maurício Link to this post

    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.



  7. Maurício
    Maurício avatar
    41 posts
    Member since:
    Jan 2011

    Posted 20 May 2014 in reply to Davide Link to this post

    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.
  8. Alex
    Admin
    Alex avatar
    129 posts

    Posted 22 May 2014 Link to this post

    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.
     
  9. Davide
    Davide avatar
    17 posts
    Member since:
    Mar 2013

    Posted 17 Jun 2014 Link to this post

    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>
  10. Todor
    Admin
    Todor avatar
    168 posts

    Posted 20 Jun 2014 Link to this post

    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.
     
Back to Top
UI for WPF is Visual Studio 2017 Ready