VintaSoft Imaging .NET SDK v8.7
In This Topic
    Process images in ASP.NET
    In This Topic

    An ASP.NET application performs all resource-intensive operation asynchronously, so the image processing should be performed also asynchronously.

    1. Image processing in ASP.NET

    The image processing in ASP.NET can be divided into the following steps:

    Client-side of ASP.NET application

    The Vintasoft.Imaging.ImageProcessing namespace (defined in Vintasoft.Imaging.Svg.js or Vintasoft.Imaging.Html5.js file) defines the following commands for image processing:

    The Vintasoft.Imaging.ImageProcessing.DocCleanup namespace (defined in Vintasoft.Imaging.DocCleanup.js file) defines the following commands for processing of document images:

    The command that change the image allows to specify how the image will be saved. WebImageProcessingCommandWithSourceChangeJS.set_ChangeSource function defines whether the changed image will be saved to the source file or to a new file.


    WebImageProcessingCommandBaseJS.execute function sends an asynchronous request for image processing. As parameters the function takes:
    Important: JQuery (version 1.11 or higher) and Vintasoft.Shared.js file are necessary for correct work of Vintasoft.Imaging.Svg.js or Vintasoft.Imaging.Html5.js file.

    Example: Here is an example that demonstrates how to determine if the image is a black-white one and convert it to black-white if not. For image processing is used a default web service.

    <script type="text/javascript">
        // create a web service for image processing
        var webService = new Vintasoft.Shared.WebServiceControllerJS("/api/Processing");
        // set the web service as the default web service for image processing
        Vintasoft.Shared.WebServiceJS.defaultImageProcessingService = webService;
    
                
        // isImageBlack command is executed successfully.
        function isImageBlack_success(answer) {
            // if image is black-white image
            if (answer.isImageBlackWhite)
                alert("Image is black-white.");
            // if image is NOT black-white image
            else {
                // create command for converting the image to a black-white image
                var convertCommand = new Vintasoft.Imaging.ImageProcessing.WebChangePixelFormatToBlackWhiteCommandJS(convert_success, error_callback);
                // execute the command
                convertCommand.execute(image);
            }
        }
    
        // Image is converted to a black-white image successfully.
        function convert_success(answer) {
            // get information about converted image
            var fileUrl = answer.imageInfo.imageId;
            var pageIndex = answer.imageInfo.pageIndex;
             // create new image source and image
            var source = new Vintasoft.Shared.WebImageSourceJS(fileUrl);
            var blackImage= new Vintasoft.Shared.WebImageJS(source, pageIndex);
            // set processed image as the first image in image viewer
            imageViewer1.get_Images().set(0, blackImage);
        }
    
        // Image processing command is failed.
        function error_callback(answer) {
            if (answer.errorMessage)
                alert(answer.errorMessage);
        }
    
        // create an image processing command
        var isImageBlackCommand = new Vintasoft.Imaging.ImageProcessing.WebIsImageBlackWhiteCommandJS(isImageBlack_success, error_callback);
        // get reference to the first image in image viewer
        var image = imageViewer1.get_Images().get_Image(0);
        // execute the command on image using the default web service
        isImageBlackCommand.execute(image);
    </script>
            
    


    Example: Here is an example that demonstrates how to invert the image stored on server and save the changes to the source file. For image processing is created a special web service.

    <script type="text/javascript">
        // create a web service for image processing
        var webService = new Vintasoft.Shared.WebServiceControllerJS("/api/Processing");
    
        // Image is inverted successfully.
        function invertCommand_success(answer) {
            // get information about processed image
            var fileUrl = answer.imageInfo.imageId;
            var pageIndex = answer.imageInfo.pageIndex;
            // create new image source and image
            var source = new Vintasoft.Shared.WebImageSourceJS(fileUrl);
            var image = new Vintasoft.Shared.WebImageJS(source, pageIndex);
            // set processed image as the first image in image viewer
            imageViewer1.get_Images().set(0, image);
        }
    
        // Image processing command is failed.
        function invertCommand_error(answer) {
            if (answer.errorMessage)
                alert(answer.errorMessage);
        }
    
        // create an image processing command
        var invertCommand = new Vintasoft.Imaging.ImageProcessing.WebInvertCommandJS(invertCommand_success, invertCommand_error);
        // get reference to the first image in image viewer
        var image = imageViewer1.get_Images().get_Image(0);
        // execute the command on image using the web service
        invertCommand.execute(image, webService);
    </script>
            
    


    Example: Here is an example that demonstrates how to detect the correct orientation of document image stored on server and save the change to a new file. For image processing is used a default web service.

    <script type="text/javascript">
        // create a web service for processing of document images
        var webService = new Vintasoft.Shared.WebServiceControllerJS("/vintasoft/api/ImageProcessingDocCleanupApi");
        // set the web service as the default web service for processing of document images
        Vintasoft.Shared.WebServiceJS.defaultImageProcessingDocCleanupService = webService;
        
        // Image is deskewed successfully.
        function deskewCommand_success(answer) {
            // get information about processed image
            var fileUrl = answer.imageInfo.imageId;
            var pageIndex = answer.imageInfo.pageIndex;
            // create new image source and image
            var source = new Vintasoft.Shared.WebImageSourceJS(fileUrl);
            var image= new Vintasoft.Shared.WebImageJS(source, pageIndex);
            // add the processed image to the end of image collection of image viewer
            imageViewer1.get_Images().add(image);
        }
        
        // Image processing command is failed.
        function deskewCommand_error(answer) {
            if (answer.errorMessage)
                alert(answer.errorMessage);
        }
    
        // get reference to the first image in image viewer
        var image = imageViewer1.get_Images().get_Image(0);
        // create an image processing command
        var deskewCommand = new Vintasoft.Imaging.ImageProcessing.DocCleanup.WebDeskewCommandJS(deskewCommand_success, deskewCommand_error);
        // specify that processed image must be saved to a new file
        deskewCommand.set_ChangeSource(false);
        // execute the command on image using the default web service
        deskewCommand.execute(image);
    </script>
            
    


    Local web service

    Depending on application architecture the web service that processes images can be based on Web API controller, WCF service or HTTP handler.
    The SDK provides the following ready-to-use web services: Important: Vintasoft.Imaging.dll, Vintasoft.Shared.dll and Vintasoft.Shared.Web.dll assemblies are necessary for correct work of Vintasoft.Imaging.Web.ApiControllers.dll, Vintasoft.Imaging.Web.WcfServices.dll or Vintasoft.Imaging.Web.HttpHandlers.dll assembly.

    Important: Vintasoft.Imaging.dll, Vintasoft.Imaging.DocCleanup.dll , Vintasoft.Shared.dll and Vintasoft.Shared.Web.dll assemblies are necessary for correct work of Vintasoft.Imaging.DocCleanup.Web.ApiControllers.dll, Vintasoft.Imaging.DocCleanup.Web.WcfServices.dll or Vintasoft.Imaging.DocCleanup.Web.HttpHandlers.dll assembly.


    2. Demo applications

    The AspNetMvcDemos project (included in the distributive package of VintaSoft Imaging .NET SDK) contains the demo (ImagingDemo view), which demonstrates how to process images in ASP.NET MVC using the web service based on Web API controller.

    The AspNetDemos project (can be found in distributive package of VintaSoft Imaging .NET SDK) contains the demo (ImagingDemo ASPX page), which demonstrates how to process images in ASP.NET WebForms using the web service based on HTTP handler.