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

Detecting change

8 Answers 105 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Christie Admin
Top achievements
Rank 1
Christie Admin asked on 23 Jul 2015, 03:34 PM

Hi,

 

I would like to know how it's possible to detect any changes to the image in the editor?

 

Thank's

Alain

8 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 27 Jul 2015, 08:09 AM
Hi Alain,

You can subscribe to the CurrentImageChanged event of the image history to be notified about changes in the current image.
this.ImageEditorUI.ImageEditor.History.CurrentImageChanged += History_CurrentImageChanged;

Please note the event is raised when the tool you are working with is committed, i.e. when the image is actually changed. You can also take a look at this SDK example to see how to work with the ToolCommitting and ToolCommitted events.

Regards,
Petya
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
0
Rob A.
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 03 Dec 2020, 01:19 AM

This doesn't actually work.  It will only trigger the event when clicking on another ImageToolItem ... it does NOT trigger from when the actual value has changed via manipulation of the slider control for that ImageToolItem.

Oddly "LostFocus" event is always being trigger which actually makes for a better event to process ImageToolItem changes.

Cheers, Rob.

 

0
Martin Ivanov
Telerik team
answered on 07 Dec 2020, 02:07 PM

Hello Rob,

Thank you for the LostFocus tip.

The CurrentImageChanged fires when the current image instance is changed. This happens when the currently executing tool is committed. A tool is committed when you click on another tool in the UI, when you click on a button in the settings UI (such button is provided only in few of the tools) or when you manually call the CommitTool() method. 

When you change settings via the tool settings UI (like moving sliders, changing texts, drawing shapes, etc.) and the tool is not yet committed, the current image is not changed. Instead an additional layer with elements previewing the applied change is displayed over the current image.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Rob A.
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 09 Dec 2020, 06:56 PM

Hi Martin,

So if I understand you correctly, there is no way to access the Hue Shift or Saturation values that change until it's committed (other than using my LostFocus approach which is not ideal but works)?  

Cheers, Rob.

0
Martin Ivanov
Telerik team
answered on 10 Dec 2020, 10:03 PM

Hello Robin,

You can access the HueShift and Saturation values before the commit via the Effect property of the corresponding ITool implementation (HueShiftTool and SaturationTool). However, this value won't be applied to the image itself until you commit the executing tool. Also, there is no event that fires when the Effect changes. If you want to listen for changes in the slider's value of the tool, you can create a custom tool deriving from HueShitTool (and another from SaturationTool) and override the GetSettingsUI() method. In the method override, you can get the Grid panel which holds a NumericPropertyEditor in the visual hierarchy, and subscribe to its ValueChanged event. 

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Richard
Top achievements
Rank 2
Veteran
answered on 03 Feb 2021, 12:23 PM

Hello folks,

I have the same problem at the moment and am trying to come up with a solid workaround...

Thanks Rob for the LostFocus approach - good find there.

Using the History.CurrentImageChanged event is OK for some of the image editor controls but as mentioned it doesn't work if you edit the Hue and haven't clicked off the tool to commit it. (It's un-intuitive and a bit clunky to expect end users to clock off a tool to commit it).

I'm trying out the LostFocus method which is nearly there, but this fires if the image is loaded, clicked on, and then the editor loses focus without being edited. This means I'd end up with users potentially being asked "Do you want to save changes" when there aren't any changes.

Overriding the GetSettingsUI method sounds interesting but a very complex way of achieving the goal.

I have raised a feature request here https://feedback.telerik.com/wpf/1505247-image-editor-implement-a-haschanges-property-on-the-image-editor for a HasChanges() property to be added to the Image Editor.

If anyone has any other suggestions on how to achieve some sort of HasChanges() functionality for the image editor I'd love to hear them 👍

Thanks - Richard

0
Richard
Top achievements
Rank 2
Veteran
answered on 03 Feb 2021, 01:25 PM

Ok I think I am able to move ahead so I'll post what seems to work for me now in case I don't come back to this issue. Hopefully it will help someone else...

The Tools have an IsDirty property that gets set when their effect values change. I found that reading this in the MouseMove event allows you to detect when a value within a tool has been changed.

Here's some pseudo code from the code behind of the view that contains a RadImageEditorUI:

public bool HasChanges { get; set; }
 
private void HistoryOnCurrentImageChanged(object sender, EventArgs e)
{
    var history = (ImageHistory)sender;
 
    if (history.CanRedo && !history.CanUndo)
    {
        HasChanges = false;
        return;
    }
 
    if (history.CanRedo || history.CanUndo)
    {
        HasChanges = true;
    }
}
 
private void ImageEditor_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
    if (ImageEditor.ImageEditor?.ExecutingTool?.IsDirty ?? false)
    {
        HasChanges = true;
    }
}

 

 

With the above, HasChanges is set true when a tool has edited the image (flip horizontal for example), or when a tool has been loaded and a value tweaked but not yet committed (resize canvas, change hue etc...).

0
Martin Ivanov
Telerik team
answered on 08 Feb 2021, 09:28 AM

Hello Richard,

Thank you for sharing your solution. I believe that this is going to be useful for someone else too.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ImageEditor
Asked by
Christie Admin
Top achievements
Rank 1
Answers by
Petya
Telerik team
Rob A.
Top achievements
Rank 2
Iron
Iron
Veteran
Martin Ivanov
Telerik team
Richard
Top achievements
Rank 2
Veteran
Share this question
or