Working With LeadTools in Web Application
Basically LeadTool is third party tool used for Image processing.
LeadTools is used to display image on window application.
If we want to use LeadTool in our web application then it needs to be used as an ActiveX controls first we need to make an ActiveX control.
While making an ActiveX control we need to write a method named should be LoadImage to load and display image in Web form.
Steps 1 – Make object of ImageViewer and declare other properties.
private _viewer as RasterImageViewer
private _ImagePath as String
private _IsMultiPage as Boolean
private _PageCount as Integer
private _PageIndex as Integer
private _OriginalScaleFactor As Long
private _ZoomMode as Boolean
Public Property ImagePath as String
Get
return _ImagePath
End Get
Set(ByVal value As String)
_ImagePath = value
End Set
End Property
Public Property ZoomMode as Boolean
Get
return _ZoomMode
End Get
Set(ByVal value As Boolean)
_ZoomMode = value
End Set
End Property
Step 2 – Declare a function named LoadImage() and in function we will do the following –
1 – Set zoom mode of image –
if _ZoomMode = False Then
_viewer.InteractiveMode = RasterViewerInteractiveMode.None
Else
_viewer.InteractiveMode = RasterViewerInteractiveMode.ZoomTo
End If
2 – Set property so that image will fit in Panel
_viewer.SizeMode = RasterPaintSizeMode.Fit
3 – Set other properties –
‘if the image path has the characteristics of a path (contains . and \)
if instr(_ImagePath, “.”) > 0 And instr(_ImagePath, “\”) > 0 then
‘Evaluate the extension
Select Case ParseExtension(_ImagePath.ToUpper)
Case “JPG”, “BMP”, “GIF”, “PNG”, “PDF”, “TIF”
Cursor.Current = Cursors.WaitCursor
dim codecs as RasterCodecs = new RasterCodecs()
codecs.Options.Pdf.Load.XResolution = 400
codecs.Options.Pdf.Load.YResolution = 400
dim ImageInfo as CodecsImageInfo
ImageInfo = codecs.GetInformation(_ImagePath, True)
_PageCount = ImageInfo.TotalPages
_IsMultiPage = _PageCount > 1
_PageIndex = 1
_viewer.Image = codecs.Load(_ImagePath, 24, CodecsLoadByteOrder.BgrOrGray, 1, 1)
‘Store the original scale factor
_OriginalScaleFactor = _viewer.ScaleFactor
Cursor.Current = Cursors.Default
Case else
_viewer.Image = nothing
Cursor.Current = Cursors.Default
End Select
End If
So your complete function looks like this –
Public Sub LoadImage()
Try
if _ZoomMode = False Then
_viewer.InteractiveMode = RasterViewerInteractiveMode.None
Else
_viewer.InteractiveMode = RasterViewerInteractiveMode.ZoomTo
End If
_viewer.Image = nothing
_viewer.SizeMode = RasterPaintSizeMode.Fit
‘if the image path has the characteristics of a path (contains . and \)
if instr(_ImagePath, “.”) > 0 And instr(_ImagePath, “\”) > 0 then
‘Evaluate the extension
Select Case ParseExtension(_ImagePath.ToUpper)
Case “JPG”, “BMP”, “GIF”, “PNG”, “PDF”, “TIF”
Cursor.Current = Cursors.WaitCursor
dim codecs as RasterCodecs = new RasterCodecs()
codecs.Options.Pdf.Load.XResolution = 400
codecs.Options.Pdf.Load.YResolution = 400
dim ImageInfo as CodecsImageInfo
ImageInfo = codecs.GetInformation(_ImagePath, True)
_PageCount = ImageInfo.TotalPages
_IsMultiPage = _PageCount > 1
_PageIndex = 1
_viewer.Image = codecs.Load(_ImagePath, 24, CodecsLoadByteOrder.BgrOrGray, 1, 1)
‘Store the original scale factor
_OriginalScaleFactor = _viewer.ScaleFactor
Cursor.Current = Cursors.Default
Case else
_viewer.Image = nothing
Cursor.Current = Cursors.Default
End Select
End If
Catch ex As System.Exception
msgbox(ex.Message)
End Try
End Sub
To call this function on our web form we will do following steps –
1 – On our aspx page where we want to show image in LeadTool we will write the code as following –
2 – To call LoadImage method of ActiveX control we need a javascript function and in that function we call LoadImage method of ActiveX control.
Example –
function LoadImageInViewer() {
var LEADControl = document.getElementById(“LEADView”);
if (LEADControl != null) {
//set path of image
LEADControl.ImagePath = strPathToLoad.value;
// Set zoom mode of Image
LEADControl.ZoomMode = true;
//call LoadImage method of ActiveX control.
LEADControl.LoadImage();
}