VintaSoft Twain .NET SDK 15.1: Документация для Веб разработчика
В этом разделе
    Как получить 48-битное цветное изображение от TWAIN сканера?
    В этом разделе
    16-битные серые изображения и 48-битные цветные изображения могут быть получены от TWAIN сканера только в режиме передачи Memory.


    Вот JavaScript код, который демонстрирует как получить 48-битные цветные изображения от TWAIN сканера:
    // acquire 48-bpp color images from TWAIN scanner
    __acquire48BppColorImagesFromTwainScanner();
    
    
    
    /**
     * Acquires 48-bpp color images from TWAIN scanner.
     */
    function __acquire48BppColorImagesFromTwainScanner() {
        // register the evaluation version of VintaSoft Web TWAIN service
        // please read how to get evaluation license in documentation: https://www.vintasoft.ru/docs/vstwain-dotnet-web/Licensing-Twain_Web-Evaluation.html
        Vintasoft.Twain.WebTwainGlobalSettingsJS.register('REG_USER', 'REG_URL', 'REG_CODE', 'EXPIRATION_DATE');
    
        // URL to the VintaSoft Web TWAIN service
        var serviceUrl = 'https://localhost:25329/api/VintasoftTwainApi';
        // a Web API controller that allows to work with TWAIN and SANE devices
        var twainService = new Vintasoft.Shared.WebServiceControllerJS(serviceUrl);
    
        // TWAIN device manager
        var deviceManager = new Vintasoft.Twain.WebTwainDeviceManagerJS(twainService);
    
        // the default settings of device manager
        var deviceManagerInitSetting = new Vintasoft.Twain.WebTwainDeviceManagerInitSettingsJS();
    
        var device = null;
        try {
            // open device manager
            deviceManager.open(deviceManagerInitSetting);
    
            // get the default TWAIN device
            device = deviceManager.get_DefaultDevice();
    
            // open TWAIN device (do not display device UI but display dialog with image scanning progress)
            device.open(false, true);
    
            // use the Memory transfer mode
            device.set_TransferMode(new Vintasoft.Twain.WebTransferModeEnumJS("Memory"));
    
            // specify that color images must be acquired from TWAIN scanner
            device.set_PixelType(new Vintasoft.Twain.WebPixelTypeEnumJS("RGB"));
            // specify the bit depth for acquired images (16 - for Epson scanners, 48 - for Canon scanners)
            device.set_BitDepth(16);
    
            var acquireModalState;
            do {
                // do one step of modal image acquisition process
                var acquireModalResult = device.acquireModalSync();
                // get state of image acquisition
                acquireModalState = acquireModalResult.get_AcquireModalState().valueOf();
    
                switch (acquireModalState) {
                    case 2:   // image is acquired
                        // get acquired image
                        var acquiredImage = acquireModalResult.get_AcquiredImage();
                        // get image as Base64 string
                        var bitmapAsBase64String = acquiredImage.getAsBase64String();
                        // update image preview
                        var previewImageElement = document.getElementById('previewImage');
                        previewImageElement.src = bitmapAsBase64String;
                        break;
                    case 4:   // image scan is failed
                        alert(acquireModalResult.get_ErrorMessage());
                        break;
                    case 9:   // image scan is finished
                        break;
                }
            }
            while (acquireModalState !== 0);
        }
        catch (ex) {
            alert(ex);
        }
        finally {
            if (device != null) {
                // close the device
                device.close();
            }
            // close the device manager
            deviceManager.close();
        }
    }
    
    


    Вот TypeScript код, который демонстрирует как получить 48-битные цветные изображения от TWAIN сканера:
    import { Component } from '@angular/core';
    
    @Component({
      selector: 'twain-scanning-demo',
      templateUrl: './twain-scanning-demo.component.html'
    })
    export class TwainScanningDemoComponent {
    
      ngOnInit() {
        // acquire 48-bpp color images from TWAIN scanner
        this.__acquireImageFromTwainScanner();
      }
    
    
      /**
       * Acquires 48-bpp color images from TWAIN scanner.
       */
      __acquireImageFromTwainScanner() {
        // register the evaluation version of VintaSoft Web TWAIN service
        // please read how to get evaluation license in documentation: https://www.vintasoft.ru/docs/vstwain-dotnet-web/Licensing-Twain_Web-Evaluation.html
        Vintasoft.Twain.WebTwainGlobalSettingsJS.register('REG_USER', 'REG_URL', 'REG_CODE', 'EXPIRATION_DATE');
    
        // URL to the VintaSoft Web TWAIN service
        let serviceUrl: string = 'https://localhost:25329/api/VintasoftTwainApi';
        // a Web API controller that allows to work with TWAIN and SANE devices
        let twainService: Vintasoft.Shared.WebServiceControllerJS = new Vintasoft.Shared.WebServiceControllerJS(serviceUrl);
    
        // TWAIN device manager
        let deviceManager: Vintasoft.Twain.WebTwainDeviceManagerJS = new Vintasoft.Twain.WebTwainDeviceManagerJS(twainService);
    
        // the default settings of device manager
        let deviceManagerInitSetting: Vintasoft.Twain.WebTwainDeviceManagerInitSettingsJS = new Vintasoft.Twain.WebTwainDeviceManagerInitSettingsJS();
    
        try {
          // open device manager
          deviceManager.open(deviceManagerInitSetting);
        }
        catch (ex) {
          alert(ex);
          return;
        }
    
        let device: Vintasoft.Twain.WebTwainDeviceJS = null;
        try {
          // get the default TWAIN device
          device = deviceManager.get_DefaultDevice();
    
          // open TWAIN device (do not display device UI but display dialog with image scanning progress)
          device.open(false, true);
    
          // use the Memory transfer mode
          device.set_TransferMode(new Vintasoft.Twain.WebTransferModeEnumJS("Memory"));
    
          // specify that color images must be acquired from TWAIN scanner
          device.set_PixelType(new Vintasoft.Twain.WebPixelTypeEnumJS("RGB"));
          // specify the bit depth for acquired images (16 - for Epson scanners, 48 - for Canon scanners)
          device.set_BitDepth(16);
    
          let acquireModalState: number;
          do {
            // do one step of modal image acquisition process
            let acquireModalResult: Vintasoft.Twain.WebTwainDeviceAcquireModalResultJS = device.acquireModalSync();
            // get state of image acquisition
            acquireModalState = acquireModalResult.get_AcquireModalState().valueOf() as number;
    
            switch (acquireModalState) {
              case 2:   // image is acquired
                // get acquired image
                let acquiredImage: Vintasoft.Twain.WebAcquiredImageJS = acquireModalResult.get_AcquiredImage();
                // get image as Base64 string
                let bitmapAsBase64String: string = acquiredImage.getAsBase64String();
                // update image preview
                let previewImageElement: HTMLImageElement = document.getElementById('previewImage') as HTMLImageElement;
                previewImageElement.src = bitmapAsBase64String;
                break;
              case 4:   // image scan is failed
                alert(acquireModalResult.get_ErrorMessage());
                break;
              case 9:   // image scan is finished
                break;
            }
          }
          while (acquireModalState !== 0);
        }
        catch (ex) {
          alert(ex);
        }
        finally {
          if (device != null) {
            // close the device
            device.close();
          }
          // close the device manager
          deviceManager.close();
        }
      }
    
    }
    
    



    Вот JavaScript код, который демонстрирует как получить 16-битные серые изображения от TWAIN сканера:
    // acquire 16-bpp grayscale images from TWAIN scanner
    __acquire16BppGrayscaleImagesFromTwainScanner();
    
    
    
    /**
     * Acquires 16-bpp grayscale images from TWAIN scanner.
     */
    function __acquire16BppGrayscaleImagesFromTwainScanner {
        // register the evaluation version of VintaSoft Web TWAIN service
        // please read how to get evaluation license in documentation: https://www.vintasoft.ru/docs/vstwain-dotnet-web/Licensing-Twain_Web-Evaluation.html
        Vintasoft.Twain.WebTwainGlobalSettingsJS.register('REG_USER', 'REG_URL', 'REG_CODE', 'EXPIRATION_DATE');
    
        // URL to the VintaSoft Web TWAIN service
        var serviceUrl = 'https://localhost:25329/api/VintasoftTwainApi';
        // a Web API controller that allows to work with TWAIN and SANE devices
        var twainService = new Vintasoft.Shared.WebServiceControllerJS(serviceUrl);
    
        // TWAIN device manager
        var deviceManager = new Vintasoft.Twain.WebTwainDeviceManagerJS(twainService);
    
        // the default settings of device manager
        var deviceManagerInitSetting = new Vintasoft.Twain.WebTwainDeviceManagerInitSettingsJS();
    
        var device = null;
        try {
            // open device manager
            deviceManager.open(deviceManagerInitSetting);
    
            // get the default TWAIN device
            device = deviceManager.get_DefaultDevice();
    
            // open TWAIN device (do not display device UI but display dialog with image scanning progress)
            device.open(false, true);
    
            // use the Memory transfer mode
            device.set_TransferMode(new Vintasoft.Twain.WebTransferModeEnumJS("Memory"));
    
            // specify that grayscale images must be acquired from TWAIN scanner
            device.set_PixelType(new Vintasoft.Twain.WebPixelTypeEnumJS("Gray"));
            // specify the bit depth for acquired images (16 - for Epson scanners, 48 - for Canon scanners)
            device.set_BitDepth(16);
    
            var acquireModalState;
            do {
                // do one step of modal image acquisition process
                var acquireModalResult = device.acquireModalSync();
                // get state of image acquisition
                acquireModalState = acquireModalResult.get_AcquireModalState().valueOf();
    
                switch (acquireModalState) {
                    case 2:   // image is acquired
                        // get acquired image
                        var acquiredImage = acquireModalResult.get_AcquiredImage();
                        // get image as Base64 string
                        var bitmapAsBase64String = acquiredImage.getAsBase64String();
                        // update image preview
                        var previewImageElement = document.getElementById('previewImage');
                        previewImageElement.src = bitmapAsBase64String;
                        break;
                    case 4:   // image scan is failed
                        alert(acquireModalResult.get_ErrorMessage());
                        break;
                    case 9:   // image scan is finished
                        break;
                }
            }
            while (acquireModalState !== 0);
        }
        catch (ex) {
            alert(ex);
        }
        finally {
            if (device != null) {
                // close the device
                device.close();
            }
            // close the device manager
            deviceManager.close();
        }
    }
    
    


    Вот TypeScript код, который демонстрирует как получить 16-битные серые изображения от TWAIN сканера:
    import { Component } from '@angular/core';
    
    @Component({
      selector: 'twain-scanning-demo',
      templateUrl: './twain-scanning-demo.component.html'
    })
    export class TwainScanningDemoComponent {
    
      ngOnInit() {
        // acquire 16-bpp grayscale images from TWAIN scanner
        this.__acquire16BppGrayscaleImagesFromTwainScanner();
      }
    
    
      /**
       * Acquires 16-bpp grayscale images from TWAIN scanner.
       */
      __acquire16BppGrayscaleImagesFromTwainScanner() {
        // register the evaluation version of VintaSoft Web TWAIN service
        // please read how to get evaluation license in documentation: https://www.vintasoft.ru/docs/vstwain-dotnet-web/Licensing-Twain_Web-Evaluation.html
        Vintasoft.Twain.WebTwainGlobalSettingsJS.register('REG_USER', 'REG_URL', 'REG_CODE', 'EXPIRATION_DATE');
    
        // URL to the VintaSoft Web TWAIN service
        let serviceUrl: string = 'https://localhost:25329/api/VintasoftTwainApi';
        // a Web API controller that allows to work with TWAIN and SANE devices
        let twainService: Vintasoft.Shared.WebServiceControllerJS = new Vintasoft.Shared.WebServiceControllerJS(serviceUrl);
    
        // TWAIN device manager
        let deviceManager: Vintasoft.Twain.WebTwainDeviceManagerJS = new Vintasoft.Twain.WebTwainDeviceManagerJS(twainService);
    
        // the default settings of device manager
        let deviceManagerInitSetting: Vintasoft.Twain.WebTwainDeviceManagerInitSettingsJS = new Vintasoft.Twain.WebTwainDeviceManagerInitSettingsJS();
    
        try {
          // open device manager
          deviceManager.open(deviceManagerInitSetting);
        }
        catch (ex) {
          alert(ex);
          return;
        }
    
        let device: Vintasoft.Twain.WebTwainDeviceJS = null;
        try {
          // get the default TWAIN device
          device = deviceManager.get_DefaultDevice();
    
          // open TWAIN device (do not display device UI but display dialog with image scanning progress)
          device.open(false, true);
    
          // use the Memory transfer mode
          device.set_TransferMode(new Vintasoft.Twain.WebTransferModeEnumJS("Memory"));
    
          // specify that grayscale images must be acquired from TWAIN scanner
          device.set_PixelType(new Vintasoft.Twain.WebPixelTypeEnumJS("Gray"));
          // specify the bit depth for acquired images (16 - for Epson scanners, 48 - for Canon scanners)
          device.set_BitDepth(16);
    
          let acquireModalState: number;
          do {
            // do one step of modal image acquisition process
            let acquireModalResult: Vintasoft.Twain.WebTwainDeviceAcquireModalResultJS = device.acquireModalSync();
            // get state of image acquisition
            acquireModalState = acquireModalResult.get_AcquireModalState().valueOf() as number;
    
            switch (acquireModalState) {
              case 2:   // image is acquired
                // get acquired image
                let acquiredImage: Vintasoft.Twain.WebAcquiredImageJS = acquireModalResult.get_AcquiredImage();
                // get image as Base64 string
                let bitmapAsBase64String: string = acquiredImage.getAsBase64String();
                // update image preview
                let previewImageElement: HTMLImageElement = document.getElementById('previewImage') as HTMLImageElement;
                previewImageElement.src = bitmapAsBase64String;
                break;
              case 4:   // image scan is failed
                alert(acquireModalResult.get_ErrorMessage());
                break;
              case 9:   // image scan is finished
                break;
            }
          }
          while (acquireModalState !== 0);
        }
        catch (ex) {
          alert(ex);
        }
        finally {
          if (device != null) {
            // close the device
            device.close();
          }
          // close the device manager
          deviceManager.close();
        }
      }
    
    }