VintaSoft Barcode .NET SDK v10.0
In This Topic
    Get an extended information about barcode in ASP.NET
    In This Topic

    1. Basic information about barcode

    Vintasoft.Barcode.Web.Services.BarcodeRecognitionResult class is a base class that stores information about recognized barcode. The class stores the type of recognized barcode, barcode value, barcode region on image, barcode recognition confidence, quality test results, etc. For 1D barcodes is defined Vintasoft.Barcode.Web.Services.BarcodeRecognition1DResult class to which is added information specific for 1D barcodes only. The same way is defined Vintasoft.Barcode.Web.Services.BarcodeRecognition2DResult class for 2D barcodes.

    2. Extended information about barcode

    If the barcode information provided by classes described in previous paragraph is not enough (for example, if it is necessary an information about search patterns of QR Code barcode), then it is necessary to perform the following steps:
    1. Create a system-independent web service for barcode recognition, which returns extended information about recognized barcode. 2. Create a system-dependent web service (HttpHandlers, ApiControllers, WcfService), which returns extended information about recognized barcode. 3. Recognize barcodes using created system-dependent web service and process the extended information about the barcode on client-side.

    2.1. Create system-independent web service for barcode recognition, which returns extended information about recognized barcode

    At beginning it is necessary to create a class, for example, MyVintasoftBarcodeWebService, which is derived from Vintasoft.Barcode.Web.Services.VintasoftBarcodeWebService class. Then override the CreateBarcodeRecognitionResult method in the class. In the method code it is necessary to add additional information about barcode to additionalInfo property of Vintasoft.Barcode.Web.Services.BarcodeRecognitionResult class.

    Here is an example of system-independent web service for barcode recognition, which returns extended information about recognized barcode:
    Imports System.Collections.Generic
    Imports System.Drawing
    Imports System.Globalization
    
    Imports Vintasoft.Barcode
    Imports Vintasoft.Barcode.BarcodeInfo
    Imports Vintasoft.Barcode.Web.Services
    Imports Vintasoft.Data
    
    Namespace Controllers
            ''' <summary>
            ''' A platform-independent web service
            ''' that handles HTTP requests from clients and allows to read and write barcodes.
            ''' </summary>
            Public Class MyVintasoftBarcodeWebService
                    Inherits VintasoftBarcodeWebService
    
                    ''' <summary>
                    ''' Initializes a new instance of the <see cref="MyVintasoftBarcodeWebService"/> class.
                    ''' </summary>
                    ''' <param name="dataStorage">Data storage that stores images.</param>
                    Public Sub New(dataStorage As IDataStorage)
                            MyBase.New(dataStorage)
                    End Sub
    
    
    
                    ''' <summary>
                    ''' Creates the barcode recognition result.
                    ''' </summary>
                    ''' <param name="info">Information about recognized barcode.</param>
                    ''' <param name="requestParams">Request params.</param>
                    ''' <returns>The barcode recognition result.</returns>
                    ''' <remarks>
                    ''' This method is overridden because we want to show how to get an extended information
                    ''' about recognized barcode, i.e. information in <see cref="BarcodeRecognitionResult"/> class
                    ''' is not enough.
    ''' Do not override this method if information provided in <see cref="BarcodeRecognitionResult"/> class ''' is enough for you.
    ''' </remarks> Protected Overrides Function CreateBarcodeRecognitionResult(info As IBarcodeInfo, requestParams As BarcodeReadRequestParams) As BarcodeRecognitionResult ' call the base method Dim result As BarcodeRecognitionResult = MyBase.CreateBarcodeRecognitionResult(info, requestParams) Dim qrInfo As QRInfo = TryCast(info, QRInfo) ' if QR barcode If qrInfo IsNot Nothing Then ' get information about patterns Dim leftBottomPatternCenter As PointF = qrInfo.LeftBottomFinderPatternCenter Dim leftTopPatternCenter As PointF = qrInfo.LeftTopFinderPatternCenter Dim rightTopPatternCenter As PointF = qrInfo.RightTopFinderPatternCenter Dim patternsInfo As New Dictionary(Of String, String)() ' add information about patterns as additional patternsInfo.Add("LeftBottomFinderPatternCenter", PatternCenterToString(leftBottomPatternCenter)) patternsInfo.Add("LeftTopFinderPatternCenter", PatternCenterToString(leftTopPatternCenter)) patternsInfo.Add("RightTopFinderPatternCenter", PatternCenterToString(rightTopPatternCenter)) result.additionalInfo = patternsInfo End If Return result End Function ''' <summary> ''' Converts a point to a string. ''' </summary> ''' <param name="p">A point.</param> ''' <returns>A string representation of point.</returns> Private Function PatternCenterToString(p As PointF) As String Return String.Format("{0}x{1}", p.X.ToString("0.00", CultureInfo.InvariantCulture), p.Y.ToString("0.00", CultureInfo.InvariantCulture)) End Function End Class End Namespace
    using System.Collections.Generic;
    using System.Drawing;
    using System.Globalization;
    
    using Vintasoft.Barcode;
    using Vintasoft.Barcode.BarcodeInfo;
    using Vintasoft.Barcode.Web.Services;
    using Vintasoft.Data;
    
    namespace AspNetMvcBarcodeDemos.Controllers
    {
        /// <summary>
        /// A platform-independent web service
        /// that handles HTTP requests from clients and allows to read and write barcodes.
        /// </summary>
        public class MyVintasoftBarcodeWebService : VintasoftBarcodeWebService
        {
    
            /// <summary>
            /// Initializes a new instance of the <see cref="MyVintasoftBarcodeWebService"/> class.
            /// </summary>
            /// <param name="dataStorage">Data storage that stores images.</param>
            public MyVintasoftBarcodeWebService(IDataStorage dataStorage)
                : base(dataStorage)
            {
            }
    
    
    
            /// <summary>
            /// Creates the barcode recognition result.
            /// </summary>
            /// <param name="info">Information about recognized barcode.</param>
            /// <param name="requestParams">Request params.</param>
            /// <returns>The barcode recognition result.</returns>
            /// <remarks>
            /// This method is overridden because we want to show how to get an extended information
            /// about recognized barcode, i.e. information in <see cref="BarcodeRecognitionResult"/> class
            /// is not enough.
    /// Do not override this method if information provided in <see cref="BarcodeRecognitionResult"/> class /// is enough for you.
    /// </remarks> protected override BarcodeRecognitionResult CreateBarcodeRecognitionResult( IBarcodeInfo info, BarcodeReadRequestParams requestParams) { // call the base method BarcodeRecognitionResult result = base.CreateBarcodeRecognitionResult(info, requestParams); QRInfo qrInfo = info as QRInfo; // if QR barcode if (qrInfo != null) { // get information about patterns PointF leftBottomPatternCenter = qrInfo.LeftBottomFinderPatternCenter; PointF leftTopPatternCenter = qrInfo.LeftTopFinderPatternCenter; PointF rightTopPatternCenter = qrInfo.RightTopFinderPatternCenter; Dictionary<string, string> patternsInfo = new Dictionary<string, string>(); // add information about patterns as additional patternsInfo.Add("LeftBottomFinderPatternCenter", PatternCenterToString(leftBottomPatternCenter)); patternsInfo.Add("LeftTopFinderPatternCenter", PatternCenterToString(leftTopPatternCenter)); patternsInfo.Add("RightTopFinderPatternCenter", PatternCenterToString(rightTopPatternCenter)); result.additionalInfo = patternsInfo; } return result; } /// <summary> /// Converts a point to a string. /// </summary> /// <param name="p">A point.</param> /// <returns>A string representation of point.</returns> private string PatternCenterToString(PointF p) { return string.Format("{0}x{1}", p.X.ToString("0.00", CultureInfo.InvariantCulture), p.Y.ToString("0.00", CultureInfo.InvariantCulture)); } } }

    2.2. Create system-dependent web service (HttpHandlers, ApiControllers, WcfService), which returns extended information about recognized barcode

    At beginning it is necessary to create a class derived from VintasoftBarcodeApiController, VintasoftBarcodeHandler or VintasoftBarcodeWcfService class. Then override the CreateWebService method in the class. The overridden method must return a new instance of MyVintasoftBarcodeWebService class.

    Here is an example of system-dependent web service based on Web API controller:
    Imports System.Collections.Generic
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.IO
    Imports System.Text.RegularExpressions
    Imports System.Web
    Imports System.Web.Mvc
    
    Imports Vintasoft.Barcode
    Imports Vintasoft.Barcode.Web.ApiControllers
    Imports Vintasoft.Barcode.Web.Services
    Imports Vintasoft.Data
    Imports Vintasoft.Shared.Web
    
    
    Namespace Controllers
            ''' <summary>
            ''' A Web API controller that handles HTTP requests from clients and
            ''' allows to read barcodes from image stored on server.
            ''' </summary>
            Public Class MyVintasoftBarcodeApiController
                    Inherits VintasoftBarcodeApiController
    
                    #Region "Constructor"
    
                    ''' <summary>
                    ''' Initializes a new instance of the <see cref="MyVintasoftBarcodeApiController"/> class.
                    ''' </summary>
                    Public Sub New()
                            MyBase.New()
                    End Sub
    
                    #End Region
    
    
    
                    #Region "Methods"
    
                    ''' <summary>
                    ''' Uploads an image file to the server.
                    ''' </summary>
                    ''' <returns>Response from the server.</returns>
                    ''' <remarks>
                    ''' Method saves an uploaded image file into "/UploadedImageFiles/{SessionID}" directory.
                    ''' </remarks>
                     _
                    Public Function UploadImageFile() As FileUploadResponseParams
                            Dim fileUrl As String = String.Empty
                            Dim answer As New FileUploadResponseParams()
                            Dim context As HttpContext = HttpContext.Current
                            Dim image As Bitmap = Nothing
                            Try
                                    ' get the session identifier
                                    Dim sessionId As String = String.Empty
                                    If context.Request.Params("sessionId") IsNot Nothing Then
                                            sessionId = context.Request.Params("sessionId").ToString()
                                    End If
    
                                    If sessionId = String.Empty Then
                                            Throw New ArgumentException("Request does not contain session ID.")
                                    End If
    
                                    ' get the uploaded file
    
                                    Dim file As HttpPostedFile = Nothing
                                    ' if request does NOT have file
                                    If context.Request.Files.Count = 0 Then
                                            Throw New ArgumentException("Request does not contain files.")
                                    Else
                                            ' if request has file
                                            ' get a reference to the first uploaded file
                                            file = context.Request.Files(0)
                                            ' if file is empty
                                            If file.ContentLength = 0 Then
                                                    Throw New ArgumentException("The first uploaded file is empty.")
                                            End If
                                    End If
    
                                    ' read first 4 bytes from the file stream
                                    Dim first4bytes As Byte() = New Byte(3) {}
                                    file.InputStream.Read(first4bytes, 0, 4)
                                    file.InputStream.Position = 0
    
                                    ' if uploaded file is PDF document
                                    If first4bytes(0) = CByte(AscW("%"C)) AndAlso first4bytes(1) = CByte(AscW("P"C)) AndAlso first4bytes(2) = CByte(AscW("D"C)) AndAlso first4bytes(3) = CByte(AscW("F"C)) Then
                                            ' get image resources of first PDF page as Bitmap
                                            image = DirectCast(GetPdfImageResourcesAsBitmap(file.InputStream, 0), Bitmap)
                                    Else
                                            ' if uploaded file is not PDF document
                                            Try
                                                    ' get image from stream
                                                    image = New Bitmap(file.InputStream)
                                            Catch generatedExceptionName As Exception
                                                    Throw New ApplicationException("The selected file is not an image.")
                                            End Try
                                    End If
    
                                    ' convert Bitmap to a Base64 string and
                                    ' add the Base64 string to a HTTP answer - this is necessary for image preview
                                    answer.base64String = ConvertBitmapToBase64(image)
    
                                    ' dispose Bitmap
                                    image.Dispose()
                                    image = Nothing
    
                                    ' create storage
                                    Dim storage As IDataStorage = CreateSessionDataStorage(sessionId)
    
                                    ' get safe filename
                                    Dim safeName As String = GetSafeFileName(Path.GetFileName(file.FileName))
                                    Dim newFileId As String = String.Format("{0}\{1}", sessionId, safeName)
                                    Dim counter As Integer = 0
                                    While storage.Contains(newFileId)
                                            newFileId = String.Format("{0}\{1}_{2}", sessionId, counter, safeName)
                                            counter += 1
                                    End While
                                    ' save file
                                    storage.AddItem(newFileId, file.InputStream)
    
                                    ' add information about saved image file into a HTTP answer
                                    answer.imageInfo = New WebImageInfo(newFileId, 0)
                                    answer.success = True
                            Catch e As Exception
                                    answer.errorMessage = e.Message
                            Finally
                                    If image IsNot Nothing Then
                                            image.Dispose()
                                            image = Nothing
                                    End If
                            End Try
                            Return answer
                    End Function
    
                    ''' <summary>
                    ''' Creates the <see cref="VintasoftBarcodeWebService"/>
                    ''' that handles HTTP requests from clients and allows to read and write barcodes.
                    ''' </summary>
                    ''' <returns>
                    ''' The <see cref="VintasoftBarcodeWebService"/>
                    ''' that handles HTTP requests from clients and allows to read and write barcodes.
                    ''' </returns>
                    Protected Overrides Function CreateWebService(sessionId As String) As VintasoftBarcodeWebService
                            Dim storage As IDataStorage = CreateSessionDataStorage(sessionId)
                            Return New MyVintasoftBarcodeWebService(storage)
                    End Function
    
                    ''' <summary>
                    ''' Creates a data storage for current session.
                    ''' </summary>
                    ''' <param name="sessionId">The session identifier.</param>
                    ''' <returns>The data storage.</returns>
                    Protected Overrides Function CreateSessionDataStorage(sessionId As String) As IDataStorage
                            Dim storagePath As String = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadedImageFiles")
                            If Not Directory.Exists(storagePath) Then
                                    Directory.CreateDirectory(storagePath)
                            End If
                            Return New StreamDataStorageOnDisk(storagePath)
                    End Function
    
                    #Region "PRIVATE"
    
                    ''' <summary>
                    ''' Converts a bitmap to a Base64 string.
                    ''' </summary>
                    Private Function ConvertBitmapToBase64(bitmap As Bitmap) As String
                            Dim array As Byte()
                            Using stream As New MemoryStream()
                                    bitmap.Save(stream, ImageFormat.Png)
                                    array = stream.ToArray()
                            End Using
                            Return String.Format("data:image/png; base64,{0}", Convert.ToBase64String(array))
                    End Function
    
                    ''' <summary>
                    ''' Returns a bitmap that represents image-resources of PDF page.
                    ''' </summary>
                    ''' <param name="stream">Stream that contains PDF document.</param>
                    ''' <param name="pageIndex">Zero based page index in PDF document.</param>
                    Private Function GetPdfImageResourcesAsBitmap(stream As Stream, pageIndex As Integer) As Bitmap
                            ' open PDF document from stream
                            Using pdfImageViewer As New PdfImageViewer(stream)
                                    Dim result As Image = Nothing
                                    Dim pdfImageResources As List(Of Bitmap) = Nothing
                                    Try
                                            If BarcodeGlobalSettings.IsDemoVersion = True AndAlso pageIndex > 0 Then
                                                    Throw New IndexOutOfRangeException("Demo version allows work only with the first page of PDF document.")
                                            End If
    
                                            ' get names of image resources
                                            Dim imageResourceNames As String() = pdfImageViewer.GetImageNames(pageIndex)
                                            If imageResourceNames.Length = 0 Then
                                                    Throw New Exception("PDF document does not contain image-resources.")
                                            End If
    
                                            ' create a list with Bitmaps of image-resources
                                            pdfImageResources = New List(Of Bitmap)()
                                            ' for each image-resource
                                            For i As Integer = 0 To imageResourceNames.Length - 1
                                                    ' get image-resource as Bitmap
                                                    Dim imageResourceAsBitmap As Bitmap = DirectCast(pdfImageViewer.GetImage(pageIndex, imageResourceNames(i)), Bitmap)
                                                    ' add Bitmap to a list
                                                    pdfImageResources.Add(imageResourceAsBitmap)
                                            Next
    
                                            ' if PDF page does not have image-resources
                                            If pdfImageResources.Count = 0 Then
                                                    result = Nothing
                                            ' if PDF page has 1 image-resource
                                            ElseIf pdfImageResources.Count = 1 Then
                                                    result = DirectCast(pdfImageResources(0), Image)
                                            Else
                                                    ' if PDF page has several image-resources
                                                    ' combine image-resource into one image
    
                                                    Dim imagePadding As Integer = 5
                                                    Dim imageHeigth As Integer = 0
                                                    Dim imageWidth As Integer = 0
                                                    Dim imageResourceCount As Integer = pdfImageResources.Count
    
                                                    ' calculate size of result image
                                                    For i As Integer = 0 To imageResourceCount - 1
                                                            Dim current As Image = DirectCast(pdfImageResources(i), Image)
                                                            If imageWidth < current.Width Then
                                                                    imageWidth = current.Width
                                                            End If
                                                            imageHeigth += current.Height
                                                    Next
                                                    imageWidth += 3
                                                    imageHeigth += (imageResourceCount + 1) * imagePadding
    
                                                    ' create result image
                                                    result = New Bitmap(imageWidth, imageHeigth, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
    
                                                    ' draw image-resources on result image
    
                                                    Using g As Graphics = Graphics.FromImage(result)
                                                            g.FillRectangle(Brushes.White, New Rectangle(0, 0, imageWidth, imageHeigth))
    
                                                            Dim dy As Integer = 1
                                                            For i As Integer = 0 To imageResourceCount - 1
                                                                    g.DrawImageUnscaled(pdfImageResources(i), New Point(1, dy))
                                                                    dy += pdfImageResources(i).Height + imagePadding
                                                            Next
                                                    End Using
                                            End If
    
                                            Return New Bitmap(result)
                                    Catch generatedExceptionName As Exception
                                            If result IsNot Nothing Then
                                                    result.Dispose()
                                            End If
    
                                            Throw
                                    Finally
                                            If pdfImageResources IsNot Nothing Then
                                                    For i As Integer = 0 To pdfImageResources.Count - 1
                                                            If pdfImageResources(i) IsNot Nothing Then
                                                                    pdfImageResources(i).Dispose()
                                                            End If
                                                    Next
                                            End If
                                    End Try
                            End Using
                    End Function
    
                    ''' <summary>
                    ''' Returns a safe filename.
                    ''' </summary>
                    ''' <param name="fileName">File name.</param>
                    ''' <returns>Safe file name.</returns>
                    Private Function GetSafeFileName(fileName As String) As String
                            Dim spacePattern As String = "(\s)"
                            Dim replace As String = "_"
                            Dim nameWithoutSpace As String = Regex.Replace(fileName, spacePattern, replace)
                            Dim charPattern As String = "[^A-Za-z0-9_.]"
                            Dim charReplace As String = "X"
                            Return Regex.Replace(nameWithoutSpace, charPattern, charReplace)
                    End Function
    
                    #End Region
    
                    #End Region
            End Class
    End Namespace
                  
    
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.Mvc;
    
    using Vintasoft.Barcode;
    using Vintasoft.Barcode.Web.ApiControllers;
    using Vintasoft.Barcode.Web.Services;
    using Vintasoft.Data;
    using Vintasoft.Shared.Web;
    
    
    namespace AspNetMvcBarcodeDemos.Controllers
    {
        /// <summary>
        /// A Web API controller that handles HTTP requests from clients and
        /// allows to read barcodes from image stored on server.
        /// </summary>
        public class MyVintasoftBarcodeApiController : VintasoftBarcodeApiController
        {
    
            #region Constructor
    
            /// <summary>
            /// Initializes a new instance of the <see cref="MyVintasoftBarcodeApiController"/> class.
            /// </summary>
            public MyVintasoftBarcodeApiController()
                : base()
            {
            }
    
            #endregion
    
    
    
            #region Methods
    
            /// <summary>
            /// Uploads an image file to the server.
            /// </summary>
            /// <returns>Response from the server.</returns>
            /// <remarks>
            /// Method saves an uploaded image file into "/UploadedImageFiles/{SessionID}" directory.
            /// </remarks>
            [HttpPost]
            public FileUploadResponseParams UploadImageFile()
            {
                string fileUrl = string.Empty;
                FileUploadResponseParams answer = new FileUploadResponseParams();
                HttpContext context = HttpContext.Current;
                Bitmap image = null;
                try
                {
                    // get the session identifier
                    string sessionId = string.Empty;
                    if (context.Request.Params["sessionId"] != null)
                        sessionId = context.Request.Params["sessionId"].ToString();
    
                    if (sessionId == string.Empty)
                        throw new ArgumentException("Request does not contain session ID.");
    
                    // get the uploaded file
    
                    HttpPostedFile file = null;
                    // if request does NOT have file
                    if (context.Request.Files.Count == 0)
                        throw new ArgumentException("Request does not contain files.");
                    // if request has file
                    else
                    {
                        // get a reference to the first uploaded file
                        file = context.Request.Files[0];
                        // if file is empty
                        if (file.ContentLength == 0)
                            throw new ArgumentException("The first uploaded file is empty.");
                    }
    
                    // read first 4 bytes from the file stream
                    byte[] first4bytes = new byte[4];
                    file.InputStream.Read(first4bytes, 0, 4);
                    file.InputStream.Position = 0;
    
                    // if uploaded file is PDF document
                    if (first4bytes[0] == (byte)'%' &&
                        first4bytes[1] == (byte)'P' &&
                        first4bytes[2] == (byte)'D' &&
                        first4bytes[3] == (byte)'F')
                    {
                        // get image resources of first PDF page as Bitmap
                        image = (Bitmap)GetPdfImageResourcesAsBitmap(file.InputStream, 0);
                    }
                    // if uploaded file is not PDF document
                    else
                    {
                        try
                        {
                            // get image from stream
                            image = new Bitmap(file.InputStream);
                        }
                        catch (Exception)
                        {
                            throw new ApplicationException("The selected file is not an image.");
                        }
                    }
    
                    // convert Bitmap to a Base64 string and
                    // add the Base64 string to a HTTP answer - this is necessary for image preview
                    answer.base64String = ConvertBitmapToBase64(image);
    
                    // dispose Bitmap
                    image.Dispose();
                    image = null;
    
                    // create storage
                    IDataStorage storage = CreateSessionDataStorage(sessionId);
    
                    // get safe filename
                    string safeName = GetSafeFileName(Path.GetFileName(file.FileName));
                    string newFileId = string.Format("{0}\\{1}", sessionId, safeName);
                    int counter = 0;
                    while (storage.Contains(newFileId))
                    {
                        newFileId = string.Format("{0}\\{1}_{2}", sessionId, counter, safeName);
                        counter++;
                    }
                    // save file
                    storage.AddItem(newFileId, file.InputStream);
    
                    // add information about saved image file into a HTTP answer
                    answer.imageInfo = new WebImageInfo(newFileId, 0);
                    answer.success = true;
                }
                catch (Exception e)
                {
                    answer.errorMessage = e.Message;
                }
                finally
                {
                    if (image != null)
                    {
                        image.Dispose();
                        image = null;
                    }
                }
                return answer;
            }
    
            /// <summary>
            /// Creates the <see cref="VintasoftBarcodeWebService"/>
            /// that handles HTTP requests from clients and allows to read and write barcodes.
            /// </summary>
            /// <returns>
            /// The <see cref="VintasoftBarcodeWebService"/>
            /// that handles HTTP requests from clients and allows to read and write barcodes.
            /// </returns>
            protected override VintasoftBarcodeWebService CreateWebService(string sessionId)
            {
                IDataStorage storage = CreateSessionDataStorage(sessionId);
                return new MyVintasoftBarcodeWebService(storage);
            }
    
            /// <summary>
            /// Creates a data storage for current session.
            /// </summary>
            /// <param name="sessionId">The session identifier.</param>
            /// <returns>The data storage.</returns>
            protected override IDataStorage CreateSessionDataStorage(string sessionId)
            {
                string storagePath = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadedImageFiles");
                if (!Directory.Exists(storagePath))
                    Directory.CreateDirectory(storagePath);
                return new StreamDataStorageOnDisk(storagePath);
            }
    
            #region PRIVATE
    
            /// <summary>
            /// Converts a bitmap to a Base64 string.
            /// </summary>
            private string ConvertBitmapToBase64(Bitmap bitmap)
            {
                byte[] array;
                using (MemoryStream stream = new MemoryStream())
                {
                    bitmap.Save(stream, ImageFormat.Png);
                    array = stream.ToArray();
                }
                return string.Format("data:image/png; base64,{0}", Convert.ToBase64String(array));
            }
    
            /// <summary>
            /// Returns a bitmap that represents image-resources of PDF page.
            /// </summary>
            /// <param name="stream">Stream that contains PDF document.</param>
            /// <param name="pageIndex">Zero based page index in PDF document.</param>
            private Bitmap GetPdfImageResourcesAsBitmap(Stream stream, int pageIndex)
            {
                // open PDF document from stream
                using (PdfImageViewer pdfImageViewer = new PdfImageViewer(stream))
                {
                    Image result = null;
                    List pdfImageResources = null;
                    try
                    {
                        if (BarcodeGlobalSettings.IsDemoVersion == true && pageIndex > 0)
                            throw new IndexOutOfRangeException("Demo version allows work only with the first page of PDF document.");
    
                        // get names of image resources
                        string[] imageResourceNames = pdfImageViewer.GetImageNames(pageIndex);
                        if (imageResourceNames.Length == 0)
                            throw new Exception("PDF document does not contain image-resources.");
    
                        // create a list with Bitmaps of image-resources
                        pdfImageResources = new List();
                        // for each image-resource
                        for (int i = 0; i < imageResourceNames.Length; i++)
                        {
                            // get image-resource as Bitmap
                            Bitmap imageResourceAsBitmap = (Bitmap)pdfImageViewer.GetImage(pageIndex, imageResourceNames[i]);
                            // add Bitmap to a list
                            pdfImageResources.Add(imageResourceAsBitmap);
                        }
    
                        // if PDF page does not have image-resources
                        if (pdfImageResources.Count == 0)
                        {
                            result = null;
                        }
                        // if PDF page has 1 image-resource
                        else if (pdfImageResources.Count == 1)
                        {
                            result = (Image)pdfImageResources[0];
                        }
                        // if PDF page has several image-resources
                        else
                        {
                            // combine image-resource into one image
    
                            int imagePadding = 5;
                            int imageHeigth = 0;
                            int imageWidth = 0;
                            int imageResourceCount = pdfImageResources.Count;
    
                            // calculate size of result image
                            for (int i = 0; i < imageResourceCount; i++)
                            {
                                Image current = (Image)pdfImageResources[i];
                                if (imageWidth < current.Width)
                                    imageWidth = current.Width;
                                imageHeigth += current.Height;
                            }
                            imageWidth += 3;
                            imageHeigth += (imageResourceCount + 1) * imagePadding;
    
                            // create result image
                            result = new Bitmap(imageWidth, imageHeigth, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    
                            // draw image-resources on result image
    
                            using (Graphics g = Graphics.FromImage(result))
                            {
                                g.FillRectangle(Brushes.White, new Rectangle(0, 0, imageWidth, imageHeigth));
    
                                int dy = 1;
                                for (int i = 0; i < imageResourceCount; i++)
                                {
                                    g.DrawImageUnscaled(pdfImageResources[i], new Point(1, dy));
                                    dy += pdfImageResources[i].Height + imagePadding;
                                }
                            }
                        }
    
                        return new Bitmap(result);
                    }
                    catch (Exception)
                    {
                        if (result != null)
                            result.Dispose();
    
                        throw;
                    }
                    finally
                    {
                        if (pdfImageResources != null)
                        {
                            for (int i = 0; i < pdfImageResources.Count; i++)
                            {
                                if (pdfImageResources[i] != null)
                                    pdfImageResources[i].Dispose();
                            }
                        }
                    }
                }
            }
    
            /// <summary>
            /// Returns a safe filename.
            /// </summary>
            /// <param name="fileName">File name.</param>
            /// <returns>Safe file name.</returns>
            private string GetSafeFileName(string fileName)
            {
                string spacePattern = @"(\s)";
                string replace = "_";
                string nameWithoutSpace = Regex.Replace(fileName, spacePattern, replace);
                string charPattern = @"[^A-Za-z0-9_.]";
                string charReplace = "X";
                return Regex.Replace(nameWithoutSpace, charPattern, charReplace);
            }
    
            #endregion
    
            #endregion
        }
    }
                    
    

    Here is an example of system-dependent web service based on HTTP handler:
    Imports System.Collections.Generic
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.IO
    Imports System.Text.RegularExpressions
    Imports System.Web
    Imports System.Web.Script.Serialization
    Imports Vintasoft.Barcode
    Imports Vintasoft.Barcode.Web.HttpHandlers
    Imports Vintasoft.Barcode.Web.Services
    Imports Vintasoft.Data
    Imports Vintasoft.Shared.Web
    
    Namespace Handlers.Barcodes
            ''' <summary>
            ''' A HTTP handler for reading and writing barcodes.
            ''' </summary>
            Public Class MyVintasoftBarcodeHandler
                    Inherits VintasoftBarcodeHandler
    
                    #Region "Constructors"
    
                    ''' <summary>
                    ''' Initializes a new instance of the <see cref="MyVintasoftBarcodeHandler"/> class.
                    ''' </summary>
                    Public Sub New()
                            MyBase.New()
                    End Sub
    
                    #End Region
    
    
    
                    #Region "Methods"
    
                    ''' <summary>
                    ''' Executes HTTP command and returns the execution result.
                    ''' </summary>
                    ''' <param name="context">An HttpContext object that provides references to
                    ''' the intrinsic server objects (for example, Request, Response, Session, and Server) used
                    ''' to service HTTP requests.</param>
                    ''' <param name="commandName">HTTP command name.</param>
                    ''' <returns>
                    ''' JSON string that contains result of HTTP command execution.
                    ''' </returns>
                    Protected Overrides Function ExecuteCommand(context As HttpContext, commandName As String) As String
                            If commandName = "UploadImageFile" Then
                                    Dim result As FileUploadResponseParams = UploadImageFile()
                                    Dim serializer As New JavaScriptSerializer()
                                    Return serializer.Serialize(result)
                            Else
                                    Return MyBase.ExecuteCommand(context, commandName)
                            End If
                    End Function
    
                    ''' <summary>
                    ''' Uploads an image file to the server.
                    ''' </summary>
                    ''' <returns>Response from the server.</returns>
                    ''' <remarks>
                    ''' Method saves an uploaded image file into "/UploadedImageFiles/{SessionID}" directory.
                    ''' </remarks>
                    Protected Function UploadImageFile() As FileUploadResponseParams
                            Dim fileUrl As String = String.Empty
                            Dim answer As New FileUploadResponseParams()
                            Dim context As HttpContext = HttpContext.Current
                            Dim image As Bitmap = Nothing
                            Try
                                    ' get the session identifier
                                    Dim sessionId As String = String.Empty
                                    If context.Request.Params("sessionId") IsNot Nothing Then
                                            sessionId = context.Request.Params("sessionId").ToString()
                                    End If
    
                                    If sessionId = String.Empty Then
                                            Throw New ArgumentException("Request does not contain session ID.")
                                    End If
    
                                    ' get the uploaded file
    
                                    Dim file As HttpPostedFile = Nothing
                                    ' if request does NOT have file
                                    If context.Request.Files.Count = 0 Then
                                            Throw New ArgumentException("Request does not contain files.")
                                    Else
                                            ' if request has file
                                            ' get a reference to the first uploaded file
                                            file = context.Request.Files(0)
                                            ' if file is empty
                                            If file.ContentLength = 0 Then
                                                    Throw New ArgumentException("The first uploaded file is empty.")
                                            End If
                                    End If
    
                                    ' read first 4 bytes from the file stream
                                    Dim first4bytes As Byte() = New Byte(3) {}
                                    file.InputStream.Read(first4bytes, 0, 4)
                                    file.InputStream.Position = 0
    
                                    ' if uploaded file is PDF document
                                    If first4bytes(0) = CByte(AscW("%"C)) AndAlso first4bytes(1) = CByte(AscW("P"C)) AndAlso first4bytes(2) = CByte(AscW("D"C)) AndAlso first4bytes(3) = CByte(AscW("F"C)) Then
                                            ' get image resources of first PDF page as Bitmap
                                            image = DirectCast(GetPdfImageResourcesAsBitmap(file.InputStream, 0), Bitmap)
                                    Else
                                            ' if uploaded file is not PDF document
                                            Try
                                                    ' get image from stream
                                                    image = New Bitmap(file.InputStream)
                                            Catch generatedExceptionName As Exception
                                                    Throw New ApplicationException("The selected file is not an image.")
                                            End Try
                                    End If
    
                                    ' convert Bitmap to a Base64 string and
                                    ' add the Base64 string to a HTTP answer - this is necessary for image preview
                                    answer.base64String = ConvertBitmapToBase64(image)
    
                                    ' dispose Bitmap
                                    image.Dispose()
                                    image = Nothing
    
                                    ' create storage
                                    Dim storage As IDataStorage = CreateSessionDataStorage(sessionId)
    
                                    ' get safe filename
                                    Dim safeName As String = GetSafeFileName(Path.GetFileName(file.FileName))
                                    Dim newFileId As String = String.Format("{0}\{1}", sessionId, safeName)
                                    Dim counter As Integer = 0
                                    While storage.Contains(newFileId)
                                            newFileId = String.Format("{0}\{1}_{2}", sessionId, counter, safeName)
                                            counter += 1
                                    End While
                                    ' save file
                                    storage.AddItem(newFileId, file.InputStream)
    
                                    ' add information about saved image file into a HTTP answer
                                    answer.imageInfo = New WebImageInfo(newFileId, 0)
                                    answer.success = True
                            Catch e As Exception
                                    answer.errorMessage = e.Message
                            Finally
                                    If image IsNot Nothing Then
                                            image.Dispose()
                                            image = Nothing
                                    End If
                            End Try
                            Return answer
                    End Function
    
                    ''' <summary>
                    ''' Creates the <see cref="VintasoftBarcodeWebService"/>
                    ''' that handles HTTP requests from clients and allows to read and write barcodes.
                    ''' </summary>
                    ''' <returns>
                    ''' The <see cref="VintasoftBarcodeWebService"/>
                    ''' that handles HTTP requests from clients and allows to read and write barcodes.
                    ''' </returns>
                    ''' <seealso cref="VintasoftBarcodeWebService"/>
                    Protected Overrides Function CreateWebService(sessionId As String) As VintasoftBarcodeWebService
                            Dim storage As IDataStorage = CreateSessionDataStorage(sessionId)
                            Return New MyVintasoftBarcodeWebService(storage)
                    End Function
    
                    ''' <summary>
                    ''' Creates a data storage for current session.
                    ''' </summary>
                    ''' <param name="sessionId">The session identifier.</param>
                    ''' <returns>The data storage.</returns>
                    Protected Overrides Function CreateSessionDataStorage(sessionId As String) As IDataStorage
                            Dim storagePath As String = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadedImageFiles")
                            If Not Directory.Exists(storagePath) Then
                                    Directory.CreateDirectory(storagePath)
                            End If
                            Return New StreamDataStorageOnDisk(storagePath)
                    End Function
    
                    #Region "PRIVATE"
    
                    ''' <summary>
                    ''' Converts a bitmap to a Base64 string.
                    ''' </summary>
                    Private Function ConvertBitmapToBase64(bitmap As Bitmap) As String
                            Dim array As Byte()
                            Using stream As New MemoryStream()
                                    bitmap.Save(stream, ImageFormat.Png)
                                    array = stream.ToArray()
                            End Using
                            Return String.Format("data:image/png; base64,{0}", Convert.ToBase64String(array))
                    End Function
    
                    ''' <summary>
                    ''' Returns a bitmap that represents image-resources of PDF page.
                    ''' </summary>
                    ''' <param name="stream">Stream that contains PDF document.</param>
                    ''' <param name="pageIndex">Zero based page index in PDF document.</param>
                    Private Function GetPdfImageResourcesAsBitmap(stream As Stream, pageIndex As Integer) As Bitmap
                            ' open PDF document from stream
                            Using pdfImageViewer As New PdfImageViewer(stream)
                                    Dim result As Image = Nothing
                                    Dim pdfImageResources As List(Of Bitmap) = Nothing
                                    Try
                                            If BarcodeGlobalSettings.IsDemoVersion = True AndAlso pageIndex > 0 Then
                                                    Throw New IndexOutOfRangeException("Demo version allows work only with the first page of PDF document.")
                                            End If
    
                                            ' get names of image resources
                                            Dim imageResourceNames As String() = pdfImageViewer.GetImageNames(pageIndex)
                                            If imageResourceNames.Length = 0 Then
                                                    Throw New Exception("PDF document does not contain image-resources.")
                                            End If
    
                                            ' create a list with Bitmaps of image-resources
                                            pdfImageResources = New List(Of Bitmap)()
                                            ' for each image-resource
                                            For i As Integer = 0 To imageResourceNames.Length - 1
                                                    ' get image-resource as Bitmap
                                                    Dim imageResourceAsBitmap As Bitmap = DirectCast(pdfImageViewer.GetImage(pageIndex, imageResourceNames(i)), Bitmap)
                                                    ' add Bitmap to a list
                                                    pdfImageResources.Add(imageResourceAsBitmap)
                                            Next
    
                                            ' if PDF page does not have image-resources
                                            If pdfImageResources.Count = 0 Then
                                                    result = Nothing
                                            ' if PDF page has 1 image-resource
                                            ElseIf pdfImageResources.Count = 1 Then
                                                    result = DirectCast(pdfImageResources(0), Image)
                                            Else
                                                    ' if PDF page has several image-resources
                                                    ' combine image-resource into one image
    
                                                    Dim imagePadding As Integer = 5
                                                    Dim imageHeigth As Integer = 0
                                                    Dim imageWidth As Integer = 0
                                                    Dim imageResourceCount As Integer = pdfImageResources.Count
    
                                                    ' calculate size of result image
                                                    For i As Integer = 0 To imageResourceCount - 1
                                                            Dim current As Image = DirectCast(pdfImageResources(i), Image)
                                                            If imageWidth < current.Width Then
                                                                    imageWidth = current.Width
                                                            End If
                                                            imageHeigth += current.Height
                                                    Next
                                                    imageWidth += 3
                                                    imageHeigth += (imageResourceCount + 1) * imagePadding
    
                                                    ' create result image
                                                    result = New Bitmap(imageWidth, imageHeigth, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
    
                                                    ' draw image-resources on result image
    
                                                    Using g As Graphics = Graphics.FromImage(result)
                                                            g.FillRectangle(Brushes.White, New Rectangle(0, 0, imageWidth, imageHeigth))
    
                                                            Dim dy As Integer = 1
                                                            For i As Integer = 0 To imageResourceCount - 1
                                                                    g.DrawImageUnscaled(pdfImageResources(i), New Point(1, dy))
                                                                    dy += pdfImageResources(i).Height + imagePadding
                                                            Next
                                                    End Using
                                            End If
    
                                            Return New Bitmap(result)
                                    Catch generatedExceptionName As Exception
                                            If result IsNot Nothing Then
                                                    result.Dispose()
                                            End If
    
                                            Throw
                                    Finally
                                            If pdfImageResources IsNot Nothing Then
                                                    For i As Integer = 0 To pdfImageResources.Count - 1
                                                            If pdfImageResources(i) IsNot Nothing Then
                                                                    pdfImageResources(i).Dispose()
                                                            End If
                                                    Next
                                            End If
                                    End Try
                            End Using
                    End Function
    
                    ''' <summary>
                    ''' Returns a safe filename.
                    ''' </summary>
                    ''' <param name="fileName">File name.</param>
                    ''' <returns>Safe file name.</returns>
                    Private Function GetSafeFileName(fileName As String) As String
                            Dim spacePattern As String = "(\s)"
                            Dim replace As String = "_"
                            Dim nameWithoutSpace As String = Regex.Replace(fileName, spacePattern, replace)
                            Dim charPattern As String = "[^A-Za-z0-9_.]"
                            Dim charReplace As String = "X"
                            Return Regex.Replace(nameWithoutSpace, charPattern, charReplace)
                    End Function
    
                    #End Region
    
                    #End Region
    
            End Class
    End Namespace
                  
    
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.Script.Serialization;
    using Vintasoft.Barcode;
    using Vintasoft.Barcode.Web.HttpHandlers;
    using Vintasoft.Barcode.Web.Services;
    using Vintasoft.Data;
    using Vintasoft.Shared.Web;
    
    namespace AspNetBarcodeDemos.Handlers.Barcodes
    {
        /// <summary>
        /// A HTTP handler for reading and writing barcodes.
        /// </summary>
        public class MyVintasoftBarcodeHandler : VintasoftBarcodeHandler
        {
    
            #region Constructors
    
            /// <summary>
            /// Initializes a new instance of the <see cref="MyVintasoftBarcodeHandler"/> class.
            /// </summary>
            public MyVintasoftBarcodeHandler()
                : base()
            {
            }
    
            #endregion
    
    
    
            #region Methods
    
            /// <summary>
            /// Executes HTTP command and returns the execution result.
            /// </summary>
            /// <param name="context">An HttpContext object that provides references to
            /// the intrinsic server objects (for example, Request, Response, Session, and Server) used
            /// to service HTTP requests.</param>
            /// <param name="commandName">HTTP command name.</param>
            /// <returns>
            /// JSON string that contains result of HTTP command execution.
            /// </returns>
            protected override string ExecuteCommand(HttpContext context, string commandName)
            {
                if (commandName == "UploadImageFile")
                {
                    FileUploadResponseParams result = UploadImageFile();
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    return serializer.Serialize(result);
                }
                else
                    return base.ExecuteCommand(context, commandName);
            }
    
            /// <summary>
            /// Uploads an image file to the server.
            /// </summary>
            /// <returns>Response from the server.</returns>
            /// <remarks>
            /// Method saves an uploaded image file into "/UploadedImageFiles/{SessionID}" directory.
            /// </remarks>
            protected FileUploadResponseParams UploadImageFile()
            {
                string fileUrl = string.Empty;
                FileUploadResponseParams answer = new FileUploadResponseParams();
                HttpContext context = HttpContext.Current;
                Bitmap image = null;
                try
                {
                    // get the session identifier
                    string sessionId = string.Empty;
                    if (context.Request.Params["sessionId"] != null)
                        sessionId = context.Request.Params["sessionId"].ToString();
    
                    if (sessionId == string.Empty)
                        throw new ArgumentException("Request does not contain session ID.");
    
                    // get the uploaded file
    
                    HttpPostedFile file = null;
                    // if request does NOT have file
                    if (context.Request.Files.Count == 0)
                        throw new ArgumentException("Request does not contain files.");
                    // if request has file
                    else
                    {
                        // get a reference to the first uploaded file
                        file = context.Request.Files[0];
                        // if file is empty
                        if (file.ContentLength == 0)
                            throw new ArgumentException("The first uploaded file is empty.");
                    }
    
                    // read first 4 bytes from the file stream
                    byte[] first4bytes = new byte[4];
                    file.InputStream.Read(first4bytes, 0, 4);
                    file.InputStream.Position = 0;
    
                    // if uploaded file is PDF document
                    if (first4bytes[0] == (byte)'%' &&
                        first4bytes[1] == (byte)'P' &&
                        first4bytes[2] == (byte)'D' &&
                        first4bytes[3] == (byte)'F')
                    {
                        // get image resources of first PDF page as Bitmap
                        image = (Bitmap)GetPdfImageResourcesAsBitmap(file.InputStream, 0);
                    }
                    // if uploaded file is not PDF document
                    else
                    {
                        try
                        {
                            // get image from stream
                            image = new Bitmap(file.InputStream);
                        }
                        catch (Exception)
                        {
                            throw new ApplicationException("The selected file is not an image.");
                        }
                    }
    
                    // convert Bitmap to a Base64 string and
                    // add the Base64 string to a HTTP answer - this is necessary for image preview
                    answer.base64String = ConvertBitmapToBase64(image);
    
                    // dispose Bitmap
                    image.Dispose();
                    image = null;
    
                    // create storage
                    IDataStorage storage = CreateSessionDataStorage(sessionId);
    
                    // get safe filename
                    string safeName = GetSafeFileName(Path.GetFileName(file.FileName));
                    string newFileId = string.Format("{0}\\{1}", sessionId, safeName);
                    int counter = 0;
                    while (storage.Contains(newFileId))
                    {
                        newFileId = string.Format("{0}\\{1}_{2}", sessionId, counter, safeName);
                        counter++;
                    }
                    // save file
                    storage.AddItem(newFileId, file.InputStream);
    
                    // add information about saved image file into a HTTP answer
                    answer.imageInfo = new WebImageInfo(newFileId, 0);
                    answer.success = true;
                }
                catch (Exception e)
                {
                    answer.errorMessage = e.Message;
                }
                finally
                {
                    if (image != null)
                    {
                        image.Dispose();
                        image = null;
                    }
                }
                return answer;
            }
    
            /// <summary>
            /// Creates the <see cref="VintasoftBarcodeWebService"/>
            /// that handles HTTP requests from clients and allows to read and write barcodes.
            /// </summary>
            /// <returns>
            /// The <see cref="VintasoftBarcodeWebService"/>
            /// that handles HTTP requests from clients and allows to read and write barcodes.
            /// </returns>
            /// <seealso cref="VintasoftBarcodeWebService"/>
            protected override VintasoftBarcodeWebService CreateWebService(string sessionId)
            {
                IDataStorage storage = CreateSessionDataStorage(sessionId);
                return new MyVintasoftBarcodeWebService(storage);
            }
    
            /// <summary>
            /// Creates a data storage for current session.
            /// </summary>
            /// <param name="sessionId">The session identifier.</param>
            /// <returns>The data storage.</returns>
            protected override IDataStorage CreateSessionDataStorage(string sessionId)
            {
                string storagePath = System.Web.Hosting.HostingEnvironment.MapPath("~/UploadedImageFiles");
                if (!Directory.Exists(storagePath))
                    Directory.CreateDirectory(storagePath);
                return new StreamDataStorageOnDisk(storagePath);
            }
    
            #region PRIVATE
    
            /// <summary>
            /// Converts a bitmap to a Base64 string.
            /// </summary>
            private string ConvertBitmapToBase64(Bitmap bitmap)
            {
                byte[] array;
                using (MemoryStream stream = new MemoryStream())
                {
                    bitmap.Save(stream, ImageFormat.Png);
                    array = stream.ToArray();
                }
                return string.Format("data:image/png; base64,{0}", Convert.ToBase64String(array));
            }
    
            /// <summary>
            /// Returns a bitmap that represents image-resources of PDF page.
            /// </summary>
            /// <param name="stream">Stream that contains PDF document.</param>
            /// <param name="pageIndex">Zero based page index in PDF document.</param>
            private Bitmap GetPdfImageResourcesAsBitmap(Stream stream, int pageIndex)
            {
                // open PDF document from stream
                using (PdfImageViewer pdfImageViewer = new PdfImageViewer(stream))
                {
                    Image result = null;
                    List pdfImageResources = null;
                    try
                    {
                        if (BarcodeGlobalSettings.IsDemoVersion == true && pageIndex > 0)
                            throw new IndexOutOfRangeException("Demo version allows work only with the first page of PDF document.");
    
                        // get names of image resources
                        string[] imageResourceNames = pdfImageViewer.GetImageNames(pageIndex);
                        if (imageResourceNames.Length == 0)
                            throw new Exception("PDF document does not contain image-resources.");
    
                        // create a list with Bitmaps of image-resources
                        pdfImageResources = new List();
                        // for each image-resource
                        for (int i = 0; i < imageResourceNames.Length; i++)
                        {
                            // get image-resource as Bitmap
                            Bitmap imageResourceAsBitmap = (Bitmap)pdfImageViewer.GetImage(pageIndex, imageResourceNames[i]);
                            // add Bitmap to a list
                            pdfImageResources.Add(imageResourceAsBitmap);
                        }
    
                        // if PDF page does not have image-resources
                        if (pdfImageResources.Count == 0)
                        {
                            result = null;
                        }
                        // if PDF page has 1 image-resource
                        else if (pdfImageResources.Count == 1)
                        {
                            result = (Image)pdfImageResources[0];
                        }
                        // if PDF page has several image-resources
                        else
                        {
                            // combine image-resource into one image
    
                            int imagePadding = 5;
                            int imageHeigth = 0;
                            int imageWidth = 0;
                            int imageResourceCount = pdfImageResources.Count;
    
                            // calculate size of result image
                            for (int i = 0; i < imageResourceCount; i++)
                            {
                                Image current = (Image)pdfImageResources[i];
                                if (imageWidth < current.Width)
                                    imageWidth = current.Width;
                                imageHeigth += current.Height;
                            }
                            imageWidth += 3;
                            imageHeigth += (imageResourceCount + 1) * imagePadding;
    
                            // create result image
                            result = new Bitmap(imageWidth, imageHeigth, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    
                            // draw image-resources on result image
    
                            using (Graphics g = Graphics.FromImage(result))
                            {
                                g.FillRectangle(Brushes.White, new Rectangle(0, 0, imageWidth, imageHeigth));
    
                                int dy = 1;
                                for (int i = 0; i < imageResourceCount; i++)
                                {
                                    g.DrawImageUnscaled(pdfImageResources[i], new Point(1, dy));
                                    dy += pdfImageResources[i].Height + imagePadding;
                                }
                            }
                        }
    
                        return new Bitmap(result);
                    }
                    catch (Exception)
                    {
                        if (result != null)
                            result.Dispose();
    
                        throw;
                    }
                    finally
                    {
                        if (pdfImageResources != null)
                        {
                            for (int i = 0; i < pdfImageResources.Count; i++)
                            {
                                if (pdfImageResources[i] != null)
                                    pdfImageResources[i].Dispose();
                            }
                        }
                    }
                }
            }
    
            /// <summary>
            /// Returns a safe filename.
            /// </summary>
            /// <param name="fileName">File name.</param>
            /// <returns>Safe file name.</returns>
            private string GetSafeFileName(string fileName)
            {
                string spacePattern = @"(\s)";
                string replace = "_";
                string nameWithoutSpace = Regex.Replace(fileName, spacePattern, replace);
                string charPattern = @"[^A-Za-z0-9_.]";
                string charReplace = "X";
                return Regex.Replace(nameWithoutSpace, charPattern, charReplace);
            }
    
            #endregion
    
            #endregion
    
        }
    }
                    
    

    2.3. Recognition of barcodes using system-dependent web service and processing the extended information about the barcode on client-side

    At beginning it is necessary to specify that we want to use the created earlier system-dependent web service for barcode recognition. Then is necessary to process the received from service information about the barcode.
    Here is an example that demonstrates how to recognize barcodes from the image and get the an extended information about the recognized barcodes:
    // web service (Web API controller), which is used for barcode recognition
    var _barcodeService = new Vintasoft.Shared.WebServiceControllerJS("vintasoft/api/MyVintasoftBarcodeApi/");
    
    // the source of barcode image
    var barcodeImage Source = new Vintasoft.Shared.WebUrlImageSourceJS("UploadedImageFiles/AllSupportedBarcodes.png");
    // barcode image
    var barcodeImage = new Vintasoft.Shared.WebImageJS(barcodeImage Source, 0);
    
    // barcode reader
    var _barcodeReader = new Vintasoft.Barcode.WebBarcodeReaderJS(_barcodeService);
    // barcode reader settings
    var _barcodeReaderSettings = new Vintasoft.Barcode.WebBarcodeReaderSettingsJS();
    
    // specify that barcode reader must recognize Code39, Code128, EAN-13 and QR barcodes
    var barcodeTypes = new Vintasoft.Barcode.WebBarcodeTypeEnumJS("Code39");
    barcodeTypes = _defaultBarcodeTypes.add("Code128");
    barcodeTypes = _defaultBarcodeTypes.add("EAN13");
    barcodeTypes = _defaultBarcodeTypes.add("QR");
    _barcodeReaderSettings.set_BarcodeType(barcodeTypes);
    
    // set the barcode recognition settings
    _barcodeReader.set_Settings(_barcodeReaderSettings);
    
    // send a request for recognizing barcodes
    var request = _barcodeReader.readBarcodes(barcodeImage, __readBarcodes_success, __readBarcodes_fail);
    
    
    // Barcodes are recognized successfully.
    function __readBarcodes_success(data) {
        // get information about recognized barcodes
        var barcodes = data.results;
        // for each barcode
        for (var i = 0; i < barcodes.length; i++) {
            var barcode = barcodes[i];
            // add information about barcode type and value to the log
            console.log("Barcode type:" + barcode.barcodeType);
            console.log("Barcode value:" + barcode.value);
            // if barcode has additional information
            if (barcode.additionalInfo != undefined) 
            {
                console.log("Additional Information:");
                // for each additional property
                for (var name in barcode.additionalInfo)
                    // add information about property name and property value to the log
                    console.log("Name: " + name + " Value: " + barcode.additionalInfo[name]);
            }
        }
    }
    
    // Barcode recognition is failed.
    function __readBarcodes_fail(data) {
        // process the error
    }