dcsimg
Results 1 to 28 of 28

Thread: VB6 - Thumbnail view based on WIA 2.0

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    VB6 - Thumbnail view based on WIA 2.0

    Background

    As camera resolutions get higher and higher VB6's native image manipulation can get bogged down. This is especially true if you need to do some processing on he thumbnails such as dealing with odd sizes, portrait images, and so on. If you want to create a "viewer" based on one of the ListView controls and ImageList controls (v. 6 or v. 5) then you need to deal with mask-transparency and you might want an outline border.

    While dropping down to API calls is fastest, the code can get complex making it harder to tailor even a known-working sample. One alternative is to make use of the WIA 2.0 Library available for XP SP1 and later and already installed as part of Vista or later.

    With WIA you also have easy access to JPEG image files' embedded thumbnail image. These are created by many cameras now and can sometimes be optionally inserted using image editing software. When available, these prescaled thumbnails can be used as-is or as the basis for scaling to a specific desired thumbnail size. Even if you rescale it this may save time over scaling the entire full-size image.


    Requirements

    Since I'm using WIA 2.0 your computer must be running Windows XP SP1 or later. For XP you may have to download and install WIA 2.0 first. However:

    Purpose
    The Windows Image Acquisition (WIA) Automation Layer is a full-featured image manipulation component that provides end-to-end image processing capabilities. The WIA Automation Layer makes it easy to acquire images from digital cameras, scanners, or Web cameras, and to rotate, scale, and annotate your image files. The WIA Automation Layer supersedes the WIA Scripting Model provided by Windows Image Acquisition (WIA) 1.0.

    Developer audience
    The WIA Automation Layer API is designed for use by Microsoft Visual Basic 6.0, Active Server Pages (ASP), and scripting programmers.

    Run-time requirements
    Applications that use the WIA Automation Layer API require Windows Vista or later. Earlier versions of Windows are not supported.
    What does this mean?

    It means now that Windows 8 is out, Windows XP is on "death watch" and Microsoft has begun removing download links for many XP add-ons.

    You'll probably have to scrounge the "Windows® Image Acquisition Automation Library" download from some 3rd party if you failed to get it while it was hot (i.e. in the last 6 years or so).

    The WIA 2.0 Automation Library documentation is found in the Windows SDK for Vista (or later) documentation (help) files.


    Of course those developing on Vista (the last release officially supporting VB6 development anyway, and in my opinion the best) have no problem except for deployment.

    But even then if you want to deploy your programs downlevel to XP SP1 through SP3 you'll want the WIAAutSDK.zip download. It contains a CHM document - but more importantly a redistributable wiaaut.dll that works on XP systems!


    MakeThumbs.cls

    This is a class wrapping several WIA objects that can be used to accept a photo/image file name and create a thumbnail StdPicture from it ready for adding to an ImageList control.

    The class has several properties you set:


    Set ThumbWidth & ThumbHeight to dimensions (in pixels) for the thumbnails. These dimensions include the 2px-wide border.

    Set FrameColor to the desired frame color for the rectangular outline. This outline will be 1px wide with a 1px inner border of the MaskColor.

    Set MaskColor to the transparency mask color to use for padding around the scaled thumbnail image from the source JPEG image.


    Then you call the InitThumbs method to create the backdrop image containing the outline and the mask.

    From there you can repeatedly call the FetchThumb method passing an image file name, getting back a StdPicture of the finished thumbnail image.

    Use the result with any image control that has a Picture property or method argument and supports a mask color for transparency. The more obvious choices are probably ImageList controls used with a ListView or TreeView control.


    JpegThumbs.vbp

    This is a sample VB6 project using MakeThumbs. You browse to a folder containing images and then it loads and displays thumbnail images for all of the image file types it supports into an ImageList and ListView. Pretty simple, and the only gingerbread here is the ability to select among 3 thumbnail sizes.


    Speed

    I won't lie and call this a speed demon, though most of the time will probably be disk I/O. Requesting the same folder (or changing the thumbnail size after loading it once) may be twice or 3 times as quick due to disk caching.

    A "first load" here seems to take about 1/8th of a second per image file for 3 to 4MB JPEGs. Doing the same steps using only VB6 native image processing techniques took me substantially longer, closer to 4 seconds per image. However I may have been using some poor techniques there too.

    InitThumbs is slow by nature and I wish I had a better way to build the backdrop. But you only need to call it once when changing the dimension or color properties, not for every loaded image.


    The Attachment

    This contains the JpegThumbs project, including the MakeThumbs class module.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by dilettante; Dec 29th, 2012 at 11:53 AM.

  2. #2
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: VB6 - Thumbnail view based on WIA 2.0

    Does WIA 2.0 generate Video's thumbnail or AutoCAD thumbnail?

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    Video files are not processed by WIA 2.0, supposedly for DRM reasons.

    I have no clue what an "AutoCAD thumbnail" might be. Here I am using JPEG thumbnails when available, otherwise scaling the main image for JPG, GIF, PNG, TIFF, and BMP files. Those are the only image file formats supported by WIA 2.0.

  4. #4
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: VB6 - Thumbnail view based on WIA 2.0

    "Those are the only image file formats supported by WIA 2.0."
    OK.

    AutoCAD is an industry leader in 2D and 3D CAD design, drafting, modeling, architectural drawing, and engineering software. Every Engineers used it.
    Attached Images Attached Images  

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    Well that's true but it is also entirely proprietary, including its file formats. Since WIA is meant for operating scanners and cameras and doing photo processing, and DWG files have draconian license requirements - it isn't surprising that these files are not supported.

    As Wikipedia says:
    There are no open source viewers for DWG files since the licensing of the libraries needed by lx-viewer now restricts their use to members of the Open Design Alliance.
    "Open Design Alliance" being doublespeak for as-closed-as-it-gets cartel as far as I can tell.
    Last edited by dilettante; Dec 29th, 2012 at 11:53 AM.

  6. #6
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    2,234

    Re: VB6 - Thumbnail view based on WIA 2.0

    Don't see an obvious way to do this in the sample, but would it be possible to get an hBitmap to use the thumbnails with an API image list? Is it just the .handle of the StdPicture object?

    I'm interested in seeing whether this outperforms IExtractImage, which I'm currently using to get thumbnails. Not sure if it's my implementation but it's quite slow on larger folders.
    Last edited by fafalone; Jun 17th, 2013 at 12:47 AM.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    I suspect this would add so much overhead that it would be far slower.

  8. #8
    New Member
    Join Date
    Nov 2013
    Posts
    2

    Re: VB6 - Thumbnail view based on WIA 2.0

    Hi dilettante !
    I have applied your code for creating thumbnails in my photo viewer application. It's great. Thank you for posting it. But I have one problem. As I display it on Full HD TV, the font of the folder browser dialog is too small to read from 2.5 m distance. As in DriveListBox and DirListBox I can increase the fontsize I used these controls to set the path for required folder. Then I assigned this path in Private Sub cmdBrowser_Click() routine to the BrowseRoot varialbe in the BrowseForFolder() function. When I run the program DriveListBox and DirListBox appear and I select the folder. Then I have to press the Browse button to display the browser dialog. The dialog appears with the correct path set and I have to click the OK button to display the thumbnails.
    What I would like is to assign the folder selected by DriveListBox and DirListBox to the NewFolder variable without having to display the dialog.
    Or to increase the font in the brouwser dialog, if it is possible.
    Can you give me advice how to do it - preferably with the sample code. Thank You in advance!

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    Your question should be asked in a general question thread over in Visual Basic 6 and Earlier because it has nothing at all to do with the MakeThumbs Class. Instead you seem to be asking an off topic common newbie question. See posts #6 and #7 in Everyone Who Hasn't Posted in the CodeBank Before PLEASE Read.

    This might get you started, though it is poor netiquette of me to abuse this thread by encouraging inappropriate behavior:

    Code:
    Private Sub cmdBrowse_Click()
        EnableUI False
    
        With New Shell32.Shell
            Set Folder = .NameSpace(BrowseRoot)
        End With
    
        Populate
    End Sub
    Hopefully I won't be admonished by a Moderator for this breach of protocol.

  10. #10
    New Member
    Join Date
    Nov 2013
    Posts
    2

    Re: VB6 - Thumbnail view based on WIA 2.0

    I am sorry to breach of protocol by posting my question in this thread. I have tryied to find solution but without any usable result. In the end I dared to ask you as I supposed you will certainly know how to solve my problem and I was right. Thank you VERY VERY VERY MUCH. This is exactly what I was looking for.

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    That's great news, I guessed right the first time!

    It is usually better to ask a question that deviates from a CodeBank topic by starting a question thread. You can always post a link back to the CodeBank thread that provides background to your question. The main difference is that this keeps the CodeBank from being cluttered by loosely related question topics, which might go on for quite a few posts before the question is resolved.

  12. #12
    New Member
    Join Date
    May 2019
    Posts
    9

    Re: VB6 - Thumbnail view based on WIA 2.0

    Dilettante ... great thumbnail viewer, thank you. Have looked far and wide to find a simple viewer which maintains aspect ratio, is simple to use, easy to install. Have got your viewer working perfectly. I have a document generation program (built in VB6 running on WinXP, now enabled through a virtual machine on Win10) which allows users to incorporate images into their documents. To date, the only way to view images was to open a specific document. With you code, I can enable all images to be viewed in one place.

    However, when I set up your code in a new Form as part of my development (with wiaaut.dll installed in the System32 folder), my VB6 project won't open and gets stalled at "Private Backdrop As WIA.ImageFile" in MakeThumbs.cls

    Can you advise?

    Also, I would like to disable the "Browse" functionality and hard code the images path instead, as I only want my clients to view the images associated with my software. Can you advise how to do this?

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    An update with a little cleanup. This version of Form1 has eliminated the use of early-bound Shell32 objects, a problem due to binary compatibility breaks by Microsoft between versions of Windows. It also uses a hard-coded photos path to simplify further - so you'll need to adjust that to run the Project.

    It still requires WIA 2.0 though, and for Win2K and WinXP you'll want the WIA 2.0 SDK installed properly. If not the entire SDK then at least the redistributable version of wiaaut.dll which your programs' installers will need to deploy as well if you plan to target WinXP.

    You can't just grab the tailored-code versions of wiaaut.dll from Vista or later and try to install those on WinXP or Win2K. It might work or it might not, but that was never an approved configuration.

    Because those OSs are completely "dead" Microsoft long ago removed the WIA 2.0 SDK from their downloads site.


    The SDK is handy for those who have it or can find a copy without added malware. First you get the documentation in it, and second you can use the redist wiaaut.dll as a private assembly post-XP. Some operations are quicker in that old version and they can make a big difference in MakeThumbs.cls which uses Vector.Add (a slow operation in later versions of the library).
    Attached Files Attached Files

  14. #14
    New Member
    Join Date
    May 2019
    Posts
    9

    Re: VB6 - Thumbnail view based on WIA 2.0

    Update looks great, thanks for hard-coded path to image files. WIA 2.0 SDK was installed on development machine, though wiaaut.dll hadn't been registered via RegSvr32, now done. All seems to work OK expect getting an error: Run-time Error '-2145320854 (8021006a)': Name Not Found" at the lines in MakeThumbs.CLS:
    Code:
    !left = Fix((ThumbWidth - 4 - ThumbScaled.Width / 2) + 2
    !top = Fix((ThumbHeight - 4 - ThumbScaled.Height / 2) + 2
    Suggestions?

  15. #15
    New Member
    Join Date
    May 2019
    Posts
    9

    Re: VB6 - Thumbnail view based on WIA 2.0

    Dilettante ... have used your revised code in JpegThumbs2, remodeled it to suit our situation (no border, fixed screen position, additional thumb size option, cancel & view buttons) and embedded code in one of our forms. VIEW button to enable highlighted thumbnail to display original image (not enlarged thumbnail) in popup form on top of thumbnail viewer (yet to be developed). This is the revised form with sample popup:
    Name:  Screenshot-1.jpg
Views: 187
Size:  29.6 KB
    Name:  Screenshot-3-ring.jpg
Views: 191
Size:  33.8 KB

    This is the code for ViewThumbnails.FRM ......

    Code:
    ' ----------------------------------------------------------------------------------------------------
    ' Purpose        : Display thumbnails of images in hard-coded folder
    ' Filename       : ViewThumbnaiils.FRM
    ' Description    : Defaults to current JM database images folder, creates thumbnails,
    '                      then displays in 4 different sizes (small, medium, large, extra-large)
    '
    ' Required Files : Needs reference to Microsoft Windows Image Acquisition Library v2.0
    '                      and specifically to wiaaut.dll
    '                      MWIA2.0 to be installed in VB6 Project References table
    '                      Files can be sourced at http://vbnet.mvps.org/index.html?code/imageapi/mswaidll.htm
    '
    ' Sequence       : Load Form
    '                        >> paint JM background, title, content bar
    '                        >> prepare thumbnail ListView
    '                        >> set path for images (this JM database)
    '                        >> generate thumbmails & populate ListView
    '                      "Form Resize" not enabled as Form has fixed dimensions to match JM windows
    '                      "ThumbnailSize" changes image size, on selection triggers new Populate sequence
    '                      "CancelButton" returns to JM Main Menu (this JM database)
    '
    ' Added          : SGS 26-May-2019
    '----------------------------------------------------------------------------------------------------
    Option Explicit
    
    Private MakeThumbs As MakeThumbs
    Private Folder As Object                        'Late-bound Shell32.Folder instance.
    
    Private Sub Form_Load()
        Dim xMenuString As String
        Dim xFunctionText As String
        Dim xSystemName As String
        
        ' Form properties set to BorderStyle=1-Fixed Single, not 2-Sizeable
        Set MakeThumbs = New MakeThumbs
        
        ' Display default JM screen background
        DisplayFormBackground Me
        Me.Show
        Me.Refresh
        
        ' Display title in Content Bar
        xMenuString = gWords.ReplaceInText(GetCurrentMenuString())
        If xMenuString = "" Then
            xMenuString = gWords.ReplaceInText(xFunctionText)
        End If
        DisplayContentBar xMenuString
        
        With ListView1
            .View = lvwIcon
            .Arrange = lvwAutoTop
            .LabelEdit = lvwManual
        End With
    
        ' Hard-coded path to images, change to suit conditions.
        With CreateObject("Shell.Application")
            Set Folder = .NameSpace("C:\dev\Valuations_V204\[xSystemName]\Images")
    
    '//*********************************************************************************************
    '
    ' Need to set FOLDER dynamically, where CurDir is location of main program
    ' and xSystemName is folder containing main database and Images is sub-folder containing images
    '        Set Folder = .NameSpace(CurDir & "\" & xSystemName & "\" & "Images")
    '
    '//*********************************************************************************************
        
        End With
        
        'Set default thumbnail size ... Small=(0), Medium=(1), Large=(2), XtraLarge=(3)
        'Thumbnail size selection triggers Click event which calls Populate
        optThumbnailSize(1).value = True
    End Sub
    
    Private Sub Populate()
        Dim T0 As Single
        Dim T1 As Single
        Dim FolderItem As Object                    'Late-bound Shell32.FolderItem instance.
        Dim ExtPos As Long
        Dim Ext As String
        Dim ImageX As Integer
        
        MousePointer = vbHourglass
        With lblStatus
            .Caption = "Loading thumbnails..."
            .Refresh
        End With
        
        T0 = Timer()                                'Start timing for thumbnail creation, displays in footer.
        
        With ImageList1
            .ListImages.Clear
            .ImageWidth = MakeThumbs.ThumbWidth
            .ImageHeight = MakeThumbs.ThumbHeight
        End With
        For Each FolderItem In Folder.Items
            With FolderItem
                If Not .IsFolder Then
                    ExtPos = InStrRev(.Name, ".")
                    If ExtPos > 0 Then
                        Ext = LCase$(Mid$(.Name, ExtPos))
                        If InStr(".jpg.jpeg.gif.png.bmp.tif.tiff", Ext) Then
                            On Error Resume Next
                            ImageX = ImageList1.ListImages.Add(, _
                                                               , _
                                                               MakeThumbs.FetchThumb(.Path)).Index
                            If Err.Number = 0 Then
                                On Error GoTo 0
                                If ListView1.Icons Is Nothing Then Set ListView1.Icons = ImageList1
                                ListView1.ListItems.Add , , .Name, ImageX
                            Else
                                On Error GoTo 0
                            End If
                            If ImageX = 32767 Then
                                MsgBox "Only showing first 32,767 images", _
                                       vbOKOnly Or vbInformation
                                Exit For
                            End If
                        End If
                    End If
                End If
            End With
        Next
        T1 = Timer() - T0
        If T1 < 0 Then T1 = T1 + 86400#
        lblStatus.Caption = "Folder """ & Folder.Self.Name _
                          & """ contains " & CStr(ImageX) & " pictures" _
                          & vbCrLf & "(" & Format$(T1, "0.0#") & " seconds)"
        MousePointer = vbDefault
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            With lblStatus
                .Move 2520, .top, .Width, .Height
            End With
            With ListView1
               .Move 0, .top, ScaleWidth, .Height
            End With
        End If
    End Sub
    
    Private Sub optThumbnailSize_Click(Index As Integer)
        With ListView1
            .ListItems.Clear
            Set .Icons = Nothing
        End With
        With MakeThumbs
            Select Case Index
                'SMALL thumbnails 5 across
                Case 0
                    .ThumbWidth = 82
                    .ThumbHeight = 63
                'MEDIUM thumbnails 3 across
                Case 1
                    .ThumbWidth = 166
                    .ThumbHeight = 125
                'LARGE thumbnails 2 across
                Case 2
                    .ThumbWidth = 270
                    .ThumbHeight = 204
                'XTRA LARGE thumbnails 1 across
                Case 3
                    .ThumbWidth = 585
                    .ThumbHeight = 446
            End Select
            .InitThumbs
        End With
        Populate
    End Sub
    
    Private Sub cmdCancelButton_Click()
        ' Return to Main Menu
        Me.Hide
        Unload Me
    End Sub
    On RUN code within VB6, get error Run-time Error '-2145320854 (8021006a)': Name Not Found at line 150 in MakeThumbs.CLS:
    Code:
    With Stamper
        With .Filters(1).Properties
            Set !ImageFile = ThumbScaled
            !left = Fix((ThumbWidth - 4 - ThumbScaled.Width) / 2) + 2
            !top = Fix((ThumbHeight - 4 - ThumbScaled.Height) / 2) + 2
        End With
        Set MakeThumb = .Apply(Backdrop)
    End With
    COMPILE appears OK. On selection of main menu option to generate thumbnails via ViewThumbnaiils.FRM, get error Run-time Error '91': Object Variable or With Block not set.

    Any suggestions?

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    Ahh, it looks like you have run afoul of one of the limitations of the "bang" (!) accessor syntax in VB. Most of the time it is used with case-insensitive keys but the Properties collection here is case-sensitive. This is still all fine until your program "breaks case conventions."

    In your program somewhere you have done so, either avoidably or otherwise. Because key values used with bang are entered into the IDE's symbol table and the symbol table enforces identifier casing to be uniform you have a problem. "Left" and "left" are not the same thing to the Properties collection.

    The fix is to avoid using bang here and revert to using String literals. While you are at it you should probably eschew relying on default properties at all and be completely explicit as in:

    Code:
        With Stamper
            With .Filters(1).Properties
                Set .Item("ImageFile").Value = ThumbScaled
                .Item("Left").Value = Fix((ThumbWidth - 4 - ThumbScaled.Width) / 2) + 2
                .Item("Top").Value = Fix((ThumbHeight - 4 - ThumbScaled.Height) / 2) + 2
            End With
            Set MakeThumb = .Apply(Backdrop)
        End With
    You should probably make the same sort of change elsewhere, such as:

    Code:
        Set Scaler = New WIA.ImageProcess
        With Scaler
            .Filters.Add .FilterInfos.Item("Scale").FilterID
            With .Filters(1).Properties
                .Item("MaximumWidth").Value = ThumbWidth - 4
                .Item("MaximumHeight").Value = ThumbHeight - 4
            End With
        End With
    And:

    Code:
    Private Sub Class_Initialize()
        BackColor = vbWindowBackground
        FrameColor = vbWindowFrame
        ThumbWidth = 164 'In pixels.
        ThumbHeight = 124 'In pixels.
        Set Stamper = New WIA.ImageProcess
        With Stamper
            .Filters.Add .FilterInfos.Item("Stamp").FilterID
        End With
    End Sub
    That might not fix all of your problems but it's a necessary change.


    The bang syntax can be handy for creating quick and dirty programs, but of course it has that subtle hazard in special cases. WIA 2.0 just happens to be one of those cases. I clearly forgot about this issue when I wrote MakeThumbs.

  17. #17
    New Member
    Join Date
    May 2019
    Posts
    9

    Re: VB6 - Thumbnail view based on WIA 2.0

    Magic!! Your amendments work like a charm, thank you very much. The thumbnails appear to be the correct size, though they have all shifted to the top-left quadrant of the individual thumbnail frame, ignoring the frame and its 2px-wide border. Any suggestions?

    Name:  Screenshot-00063_29-May-19_14.51.45PM.jpg
Views: 165
Size:  37.7 KB

    The use of "bang syntax" or otherwise is well above my pay grade, my VB6 experience is very limited. We're adding some sizzle to a 30yr old legacy product and I'm fiddling around the edges. My programmers have all retired and I don't know if they used normal case conventions in other parts of the program.

    Thanks again for your assistance.

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    I suspect that here:

    Code:
        With Stamper
            With .Filters(1).Properties
                Set .Item("ImageFile").Value = ThumbScaled
                .Item("Left").Value = Fix((ThumbWidth - 4 - ThumbScaled.Width) / 2) + 2
                .Item("Top").Value = Fix((ThumbHeight - 4 - ThumbScaled.Height) / 2) + 2
            End With
            Set MakeThumb = .Apply(Backdrop)
        End With
    ... the values of ThumbWidth and ThumbHeight are 0 or very small.

    Anyway, something there is resulting in Left and Top values that are negative. Don't you think?

  19. #19
    New Member
    Join Date
    May 2019
    Posts
    9

    Re: VB6 - Thumbnail view based on WIA 2.0

    OK, thank you. Turns out each thumbnail size requires a different value for the last number in the Left & Top equations, otherwise other sizes are off-center. Images below show how S, M, L thumbnails are all placed differently when Small thumbnail values are Left=42 and Top=33:

    Small Thumbnails
    Name:  Screenshot-00074_30-May-19_09.24.28AM.jpg
Views: 146
Size:  16.2 KB

    Medium thumbnail
    Name:  Screenshot-00073_30-May-19_09.24.15AM.jpg
Views: 146
Size:  17.1 KB

    Large thumbnail
    Name:  Screenshot-00071_30-May-19_09.23.52AM.jpg
Views: 145
Size:  18.8 KB

    Code:
        With Stamper
            With .Filters(1).Properties
                Set .Item("ImageFile").value = ThumbScaled
                .Item("Left").value = Fix((ThumbWidth - 4 - ThumbScaled.Width) / 2) + 2
                .Item("Top").value = Fix((ThumbHeight - 4 - ThumbScaled.Height) / 2) + 2
    ' Small            .Item("Left").value = Fix((ThumbWidth - 4 - ThumbScaled.Width) / 2) + 42
    ' Small            .Item("Top").value = Fix((ThumbHeight - 4 - ThumbScaled.Height) / 2) + 33
    ' Medium         .Item("Left").value = Fix((ThumbWidth - 4 - ThumbScaled.Width) / 2) + 83
    ' Medium         .Item("Top").value = Fix((ThumbHeight - 4 - ThumbScaled.Height) / 2) + 63
    ' Large            .Item("Left").value = Fix((ThumbWidth - 4 - ThumbScaled.Width) / 2) + 134
    ' Large            .Item("Top").value = Fix((ThumbHeight - 4 - ThumbScaled.Height) / 2) + 102
    ' X-Large         .Item("Left").value = Fix((ThumbWidth - 4 - ThumbScaled.Width) / 2) + 289
    ' X-Large         .Item("Top").value = Fix((ThumbHeight - 4 - ThumbScaled.Height) / 2) + 221
            End With
            Set MakeThumb = .Apply(Backdrop)
        End With
    Can the variable below be incorporated into IF statements inside [WITH STAMPER / END WITH ] to accommodate different thumbnail sizes?
    Code:
    optThumbnailSize(x).value = True

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    In the original program that assignment triggers:

    Code:
    Private Sub optThumbnailSize_Click(Index As Integer)
        With MakeThumbs
            Select Case Index
                Case 0
                    .ThumbWidth = 84
                    .ThumbHeight = 64
                Case 1
                    .ThumbWidth = 164
                    .ThumbHeight = 124
                Case 2
                    .ThumbWidth = 204
                    .ThumbHeight = 154
            End Select
            .InitThumbs
        End With
        If Folder Is Nothing Then
            tmrSetFocus.Enabled = True 'Defer setting focus.
        Else
            EnableUI False
            Populate
        End If
    End Sub
    And that should address the issue of thumbnail sizes. I'm not sure why you are changing things within MakeThumbs.cls aside from the "bang" replacements we discussed above.

  21. #21
    New Member
    Join Date
    May 2019
    Posts
    9

    Re: VB6 - Thumbnail view based on WIA 2.0

    Fair point. MakeThumbs.cls and Thumb sizes now back to original. Result is:

    Small thumbs
    Name:  Screenshot-00097_30-May-19_20.55.18PM.jpg
Views: 136
Size:  15.6 KB

    Medium thumbs
    Name:  Screenshot-00098_30-May-19_20.55.32PM.jpg
Views: 137
Size:  17.3 KB

    Large thumbs
    Name:  Screenshot-00099_30-May-19_20.55.49PM.jpg
Views: 136
Size:  18.2 KB

    Suggested addition for error trapping causes Compile Error: Variable not defined and stops at tmrSetFocus.Enabled = True

  22. #22

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    There isn't any tmrSetFocus in the version in post #13 above so that line of code shouldn't be there either. It was associated with the cmdBrowse button in the earlier example.


    I'm not sure how it is happening, but in this code:

    Code:
        'Stamp scaled thumb centered on backdrop, return result.
        With Stamper
            With .Filters(1).Properties
                Set .Item("ImageFile").Value = ThumbScaled
                .Item("Left").Value = Fix((ThumbWidth - 4 - ThumbScaled.Width) / 2) + 2
                .Item("Top").Value = Fix((ThumbHeight - 4 - ThumbScaled.Height) / 2) + 2
            End With
            Set MakeThumb = .Apply(Backdrop)
        End With
    ... I think you have somehow changed ThumbWidth and ThumbHeight to 0 after calling InitThumbs, and we've gone around in a circle because we've already been here. See post #18 above.


    I can break the demo that way myself by adding two lines:

    Code:
    Private Sub optThumbnailSize_Click(Index As Integer)
        With ListView1
            .ListItems.Clear
            Set .Icons = Nothing
        End With
        With MakeThumbs
            Select Case Index
                Case 0
                    .ThumbWidth = 84
                    .ThumbHeight = 64
                Case 1
                    .ThumbWidth = 164
                    .ThumbHeight = 124
                Case 2
                    .ThumbWidth = 204
                    .ThumbHeight = 154
            End Select
            .InitThumbs
            .ThumbWidth = 0
            .ThumbHeight = 0
        End With
        Populate
    End Sub

  23. #23
    New Member
    Join Date
    May 2019
    Posts
    9

    Re: VB6 - Thumbnail view based on WIA 2.0

    Circles, yes. I didn't add tmrSetFocus, it appeared in your code at #20, now removed.

    I've checked and ThumbWidth & ThumbHeight are as expected after .InitThumbs
    Name:  Screenshot-00100_31-May-19_09.57.36AM.png
Views: 112
Size:  15.3 KB

    So I've gone back to your original code in post #13 (JpegThumbs2), inserted that into my project (including your suggested 'bang' replacements to MakeThumbs.cls in post #16) and we're back to the image in post #17.
    Name:  Screenshot-00101_31-May-19_10.14.01AM.jpg
Views: 115
Size:  29.0 KB

    Now I'm stumped.

  24. #24

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    I'm out of guesses where things might be going wrong. Look for places you assign to ThumbWidth and ThumbHeight properties and call InitThumbs. I can't imagine anything else that might produce the results you are seeing.

    Somewhere you must be changing ThumbWidth and ThumbHeight to 0 after calling InitThumbs. It also looks like you don't call InitThumbs again each time the Thumbnail size is changed.

  25. #25
    New Member
    Join Date
    May 2019
    Posts
    9

    Re: VB6 - Thumbnail view based on WIA 2.0

    The last example was your exact code from post #13, UNCHANGED but with your suggestions from post #16. I added a MsgBox to generate the values of SelectCase, ThumbWidth & ThumbHeight immediately after InitThumbs. No other changes by me whatsoever. It is call from my program and opens in a separate distinct window. Looks like I might have to abandon using JpegThumbs2. Too bad, it would have made a great addition to my next release.

  26. #26

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    This version should be harder to break.

    It replaced uses of the ! operator as described in post #16 above, but more importantly it changes InitThumbs() to require the values for ThumbWidth and ThumbHeight as arguments and it makes the corresponding properties read-only. This eliminates an opportunity for misuse that could lead to the symptoms you have been seeing.
    Attached Files Attached Files

  27. #27
    New Member
    Join Date
    May 2019
    Posts
    9

    Re: VB6 - Thumbnail view based on WIA 2.0

    Following post #25, I decided to start over from scratch with JpegThumbs2 from post #13 including your modifications in post #16. As a standalone project it worked as expected. When this was incorporated into my project, it didn't work, so I did a variable-by-variable comparison with your code and my project to see if there were any duplicates. Only one, which was easy to amend. Now it works within my project and looks FANTASTIC.

    Name:  Screenshot-00102_02-Jun-19_09.19.58AM.jpg
Views: 70
Size:  39.9 KB

    Then post #26 arrived and I've used your new code and incorporated that into my project (including my repositioning of the form) and it works perfectly. Thank you for taking the time to amend ver2 and for your perseverance. Very much appreciated.
    SGS

  28. #28

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,115

    Re: VB6 - Thumbnail view based on WIA 2.0

    Glad it helped.

    A reminder to those supporting post-XP OSs:

    Even though post-XP versions of Windows contain a wiaaut.dll already, the newer versions have DRM-protections and other limitations that can cause some operations to be very slow. For best performance your applications will need Side-by-Side manifests and the redist version of the DLL instead.

    Or you could skip WIA and write equivalent code using the GDI+ Flat API directly.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width