Vba to capture camera image (1 Viewer)

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 11:45
Joined
Apr 1, 2019
Messages
731
Hi, i'm working on my safety system "hazard" database and its comming along nicely thanks to support from the forum amongst others. Now, what i'd like to do is sit a new employee in front of the laptop camera & take a photo of them for the record. I cannot find any reference to this being done. If anyone has any suggestions, then i'd be greatful to hear their experiences. Cheers.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:45
Joined
May 7, 2009
Messages
19,237
there is already Similar db I made.
no need to wander further.
go to Sample Databases->Cheap Alternative to Access Imagine.
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 11:45
Joined
Apr 1, 2019
Messages
731
Guys, thanks. Will have a go. Cheers
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 11:45
Joined
Apr 1, 2019
Messages
731
arnelgp, your demo works great. I wish to capture images very similarly to your demo. I note that the saved image is .BMP and not .JPG. All of my "imported" images are .jpg. I already have a couple of routines to reduce the size & rotate imported images, so shouldn't be difficult to adapt these to your code. I don't see a choice of formats in the setup. Any thoughts would be appreciated.
 

moke123

AWF VIP
Local time
Today, 18:45
Joined
Jan 11, 2013
Messages
3,919
I tried both arnels and the version colin linked to. They are virtually the same with the exception that arnels saves as a bitmap and colins can be saved in different formats.
I believe that bitmaps display better in access than jpgs.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:45
Joined
May 7, 2009
Messages
19,237
I used this to convert the image:
Code:
Option Compare Database
Option Explicit

Public Enum wiaFormat
    BMP = 0
    GIF = 1
    JPEG = 2
    PNG = 3
    TIFF = 4
End Enum
 
'---------------------------------------------------------------------------------------
' Procedure : WIA_ConvertImage
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Convert an image's format using WIA
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
'             (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: Uses Late Binding, so none required
'
' Windows Image Acquisition (WIA)
'             https://msdn.microsoft.com/en-us/library/windows/desktop/ms630368(v=vs.85).aspx
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sInitialImage : Fully qualified path and filename of the original image to resize
' sOutputImage  : Fully qualified path and filename of where to save the new image
' lFormat       : Format to convert the image into
' lQuality      : Quality level to be used for the conversion process (1-100)
'
' Usage:
' ~~~~~~
' Call WIA_ConvertImage("C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg", _
'                       "C:\Users\MyUser\Desktop\Chrysanthemum_2.jpg", _
'                       JPEG)
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2017-01-18              Initial Release
' 2         2018-09-20              Updated Copyright
'---------------------------------------------------------------------------------------
Public Function WIA_ConvertImage(sInitialImage As String, _
                                 sOutputImage As String, _
                                 lFormat As wiaFormat, _
                                 Optional lQuality As Long = 85) As Boolean
    On Error GoTo Error_Handler
    Dim oWIA                  As Object    'WIA.ImageFile
    Dim oIP                   As Object    'ImageProcess
    Dim sFormatID             As String
    Dim sExt                  As String
 
    'Convert our Enum over to the proper value used by WIA
    Select Case lFormat
        Case 0
            sFormatID = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
            sExt = "BMP"
        Case 1
            sFormatID = "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"
            sExt = "GIF"
        Case 2
            sFormatID = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
            'sExt = "JPEG"
            sExt = "JPG"
        Case 3
            sFormatID = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
            sExt = "PNG"
        Case 4
            sFormatID = "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"
            sExt = "TIFF"
    End Select
 
    If lQuality > 100 Then lQuality = 100
 
    'Should check if the output file already exists and if so,
    'prompt the user to overwrite it or not
 
    Set oWIA = CreateObject("WIA.ImageFile")
    Set oIP = CreateObject("WIA.ImageProcess")
 
    oIP.Filters.Add oIP.FilterInfos("Convert").FilterID
    oIP.Filters(1).Properties("FormatID") = sFormatID
    oIP.Filters(1).Properties("Quality") = lQuality
 
    oWIA.LoadFile sInitialImage
    Set oWIA = oIP.Apply(oWIA)
    'Overide the specified ext with the appropriate one for the choosen format
    oWIA.SaveFile Left(sOutputImage, InStrRev(sOutputImage, ".")) & LCase(sExt)
    WIA_ConvertImage = True
 
Error_Handler_Exit:
    On Error Resume Next
    If Not oIP Is Nothing Then Set oIP = Nothing
    If Not oWIA Is Nothing Then Set oWIA = Nothing
    Exit Function
 
Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: WIA_ConvertImage" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Function
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 11:45
Joined
Apr 1, 2019
Messages
731
arnelgp, apologies for the late reply. I should be able to build a good suite of image manipulation tools now.
 

isladogs

MVP / VIP
Local time
Today, 23:45
Joined
Jan 14, 2017
Messages
18,217
Just to confirm, jpg files usually do not work well in Access due to their lossy format.
It is much better to use either BMP or PNG.
I prefer PNG as these are much smaller files but a similar quality to BMP
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 11:45
Joined
Apr 1, 2019
Messages
731
Isladogs, thanks for the tip. I'm currently using .jpg's for employee photos and use a code module to reduce their size to 2000x2000 pixels (i think that's what i've done). I quickly learn't that a modern phone can produce an image of 10mb, which proved difficult for access, in particular printing said image in a report didn't work till i reduced the file size. Really appreciate the support.
 

Users who are viewing this thread

Top Bottom