Victor Image Processing Library How-to Tips

Create a 64-bit VB.NET App with the Victor Library

The Victor Image Processing Library for 64-bit Windows has all the same functions and capabilities that the 32-bit version of the library has. In the .net world we use a viclib64 interface to simplify calls into the Victor Library dlls.

Begin by starting Visual Studio and creating a new VB.NET desktop app. Then follow these steps


Download the VB.NET source code for the VIC64 VB Sample



Victor Library 64-bit VB.NET Sample Application Source Code

This is a simple VB.NET app that will open, display, and print an image. Requires Victor Image Processing Library for 64-bit Windows.
    
Imports viclib64
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Printing
Public Class Form1
    ' vimage is the global image descriptor for the current Victor Library image in memory
    Dim vimage As vicwin.imgdes
    Private Sub mnu_Open_Click(sender As Object, e As EventArgs) Handles mnu_Open.Click
        Dim rcode As Integer
        Dim timage As vicwin.imgdes
        Dim myStream As Stream
        Dim filename As String
        Dim openFileDialog1 As New OpenFileDialog()
        openFileDialog1.Filter = "Image Files |*.bmp;*.gif;*.jpg;*.png;*.tif|All files |*.*"
        If openFileDialog1.ShowDialog() = DialogResult.OK Then
            myStream = openFileDialog1.OpenFile()
            If Not (myStream Is Nothing) Then
                filename = openFileDialog1.FileName
                
    ' Puts the image into globally defined vimage
                openfile_to_vimage(filename) ' Defined below
                display_vimage()             ' Defined below   
                myStream.Close()
            End If
        End If
   End Sub
    Private Sub mnu_New_Click(sender As Object, e As EventArgs) Handles mnu_New.Click
        Dim rcode As Integer
        Dim timage As vicwin.imgdes
        rcode = vicwin.allocimage(timage, 256, 256, 8)
        If rcode = vicwin.NO_ERROR Then
            rcode = vicwin.zeroimage(255, timage)  ' Start with a white picture box
            vicwin.freeimage(vimage)
            vimage = timage
            display_vimage()        ' Defined below
        End If
    End Sub
    Private Sub mnu_Save_Click(sender As Object, e As EventArgs) Handles mnu_Save.Click
        Dim rcode As Integer
        
    ' To do: Add savefiledialog to enter filename and filetype
        rcode = vicwin.savetif("test.tif", vimage, 0)
    End Sub
    Private Sub mnu_Print_Click(sender As Object, e As EventArgs) Handles mnu_Print.Click
        Dim pdoc As PrintDocument
        pdoc = New PrintDocument
        AddHandler pdoc.PrintPage, AddressOf dotheprint     ' dotheprint is defined below
        pdoc.Print()
    End Sub
    Private Sub mnu_Exit_Click(sender As Object, e As EventArgs) Handles mnu_Exit.Click
        vicwin.freeimage(vimage)
    End Sub
    Public Sub display_vimage()
        Dim swidth As Integer
        Dim slength As Integer
        If vimage.hBitmap <> 0 Then
            swidth = vimage.endx - vimage.stx + 1
            slength = vimage.endy - vimage.sty + 1
            PictureBox1.Image = Image.FromHbitmap(vimage.hBitmap)
            PictureBox1.Width = swidth
            PictureBox1.Height = slength
            PictureBox1.Refresh()
        End If
    End Sub
    Public Sub openfile_to_vimage(filename As String)
        Dim bdata As vicwin.BITMAPINFOHEADER
        Dim gdata As vicwin.GifData
        Dim jdata As vicwin.JpegData
        Dim tdata As vicwin.TiffData
        Dim pdata As vicwin.PngData
        Dim j, rcode, ftype As Integer
        Dim length, width, vbitcount As Integer
        Dim fileType As String
        Dim newimage As vicwin.imgdes
        Dim tempimage As vicwin.imgdes
        Dim xres As Integer
        Dim yres As Integer
        Dim resunit As Integer
        Dim totalpages As Integer
        Dim arrayelems As Integer
        Dim pageIndex As Integer
        On Error Resume Next
        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor ' Change mouse pointer to hourglass
    ' Initialize variables
        rcode = vicwin.BAD_FTPE
    ' Try all filetypes based on popularity
        
    ' jpeg
        rcode = vicwin.jpeginfo(filename, jdata)
        If (rcode = vicwin.NO_ERROR) Then
            width = jdata.width
            length = jdata.length
            vbitcount = jdata.vbitcount
            rcode = vicwin.allocimage(tempimage, width, length, vbitcount)
            If (rcode = vicwin.NO_ERROR) Then
                rcode = vicwin.loadjpg(filename, tempimage)
            End If
            GoTo done
        End If
    ' tiff
        rcode = vicwin.tiffgetpageinfo(filename, totalpages, 0, arrayelems)
        If (rcode = vicwin.NO_ERROR) Then
            pageIndex = 0 ' get info about the first page
            rcode = vicwin.tiffinfopagebyindex(filename, tdata, pageIndex)
            rcode = vicwin.tiffgetxyresolutionpagebyindex(filename, xres, yres, resunit, pageIndex)
            width = tdata.width
            length = tdata.length
            vbitcount = tdata.vbitcount
            rcode = vicwin.allocimage(tempimage, width, length, vbitcount)
            If (rcode = vicwin.NO_ERROR) Then
                rcode = vicwin.loadtifpagebyindex(filename, tempimage, pageIndex)
    ' 16-bit grayscale
                If rcode = vicwin.NO_ERROR And tdata.BitsPSample = 16 And tdata.SamplesPPixel = 1 Then
                    rcode = vicwin.allocimage(newimage, width, length, 8)
                    rcode = vicwin.convertgray16to8(tempimage, newimage)
                    vicwin.freeimage(tempimage)
                    vicwin.copyimgdes(newimage, tempimage)
                End If
            End If
            GoTo done
        End If
    ' gif
        rcode = vicwin.gifinfo(filename, gdata)
        If (rcode = vicwin.NO_ERROR) Then
            width = gdata.width
            length = gdata.length
            vbitcount = gdata.vbitcount
            rcode = vicwin.allocimage(tempimage, width, length, vbitcount)
            If (rcode = vicwin.NO_ERROR) Then
                rcode = vicwin.loadgif(filename, tempimage)
            End If
            GoTo done
        End If
    'png
        rcode = vicwin.pnginfo(filename, pdata)
        If (rcode = vicwin.NO_ERROR) Then
            width = pdata.width
            length = pdata.length
            vbitcount = pdata.vbitcount
            rcode = vicwin.allocimage(tempimage, width, length, vbitcount)
            If (rcode = vicwin.NO_ERROR) Then
                rcode = vicwin.loadpng(filename, tempimage)
            End If
            GoTo done
        End If
    'bmp
        rcode = vicwin.bmpinfo(filename, bdata)
        If (rcode = vicwin.NO_ERROR) Then
            width = bdata.biWidth
            length = bdata.biHeight
            vbitcount = bdata.biBitCount
            rcode = vicwin.allocimage(tempimage, width, length, vbitcount)
            If (rcode = vicwin.NO_ERROR) Then
                rcode = vicwin.loadbmp(filename, tempimage)
            End If
            GoTo done
        End If
done:
        If rcode = vicwin.NO_ERROR Then
    ' Replace previous image
            vicwin.freeimage(vimage)
            vimage = tempimage
        End If
        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default ' Reset the mouse pointer.
    End Sub
    Public Sub dotheprint(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
        Dim prtimage As Image
        Dim pwidth As Integer
        Dim plength As Integer
        Dim pinches As Integer
        Dim pcalht As Integer
        prtimage = Image.FromHbitmap(vimage.hBitmap)  ' vimage is the globally defined image
        pwidth = vimage.endx - vimage.stx + 1
        plength = vimage.endy - vimage.sty + 1
        pinches = 300   ' 300 equals 3 inches, so print image 3 inches wide on paper
        pcalht = pinches * plength / pwidth
        ev.Graphics.DrawImage(prtimage, 0, 0, pinches, pcalht)  ' Calculate correct aspect ratio
        ev.HasMorePages = False
    End Sub
End Class
Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code




Copyright © 2014 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.