Tutorials
/ Other Technologies
/ Use and handling of the Selection Area
Use and handling of the Selection Area
In This Topic
Overview
This tutorial shows how to work with selection area (also known as Region of Interest, or ROI) in a C# REST service project with ASP.NET Web API 2 from the .NET Framework.
DocuVieware™ requires .NET Framework 4.6 or above.
Summary
The starting point of this tutorial is the application you have at the end of Serving DocuVieware through a REST API, it is a prerequisite so if you do not have it, please follow this tutorial first.
You are going to add three buttons on your DocuVieware™ client page, one will simply output the coordinates of the selection area (if any), another one will clear it and finally the last button will apply a negative filter on the selected area.
Display the ROI coordinates
This is done client side very easily, add a button that will call a JavaScript function on the onclick event. Here is the code:
Clear the ROI
It is often usefull to have a button to clear the ROI (i.e. reset the selection area) and it is done the exact same way. Add button that calls a JavaScript function on the onclick event.
Apply Negative on the ROI
Now you are going to use a CustomAction to apply the Negative filter on the selected area. You will need to send the ROI coordinates server side, set a ROI on the actual image and apply the filter on it.
Step 1 : Add the button and the JavaScript function that will be executed on the onclick event. We also want the selected area to be reset if the operation is successful.
Step 2 : You are going to need a class to define the parameters that well be sent (i.e. the ROI coordinates). Simply add a new class called RegionOfInterest.cs in your Models folder like this:
Step 3 : Subscribe to the CustomAction event and dispatch to the event handler (please refer to Client/Server coming and going with Custom Actions if you need more information about this mechanism).
Step 4 : You can implement the custom action handler itself. Add a CustomActions.cs class to your project if there isn't one already.
What you will be doing here is first retrieve the image object, set the ROI on it based on the coordinates received from the client side, apply the filter on it and finally redraw the page.
Here is the source code to achieve this:
See Also