Results 1 to 9 of 9

Thread: Image Viewer

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,070

    Image Viewer

    Attached is a Picture Viewer. It does not have a bunch of fancy features, because the intent was to use as much of the screen as possible for the image itself. Inspiration for this program came from dilettante with his "Drop Send Pic".
    https://www.vbforums.com/showthread....mage-to-Base64
    Before anyone tells me that I could have just loaded the files directly into the Picture Box or the form Picture, I had difficulty in meeting the objectives doing it that way. I needed to not only adjust the container to suit the size of the image, but also to adjust the container for the size of the screen. I loaded the file into a byte array, and then I used a Picture Box because it was the only thing that would support "AutoRedraw". My intent is to eventually produce a remote Picture Viewer similar to dilettantes.

    J.A. Coutts

    Updated: 06/13/2021
    Updated: 06/20/2021
    Updated: 06/22/2021
    Updated: 06/24/2021
    Updated: 06/25/2021
    Attached Files Attached Files
    Last edited by couttsj; Jun 25th, 2021 at 01:07 PM.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,497

    Re: Image Viewer

    I wouldn't expect OleLoadPicture() to handle any image file data that VB's LoadPicture() doesn't.

    WIA 2.0 is a COM wrapper for a bunch of cameras and scanners stuff but also several GDI+ operations. You can use it to load BMP, GIF, JPEG, PNG, and TIFF images as a StdPicture object.

    Example:

    Code:
        With New WIA.Vector
            .BinaryData = ByteBuffer
            Set oPic = .Picture
        End With

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,070

    Re: Image Viewer

    Quote Originally Posted by dilettante View Post
    I wouldn't expect OleLoadPicture() to handle any image file data that VB's LoadPicture() doesn't.

    WIA 2.0 is a COM wrapper for a bunch of cameras and scanners stuff but also several GDI+ operations. You can use it to load BMP, GIF, JPEG, PNG, and TIFF images as a StdPicture object.
    Works like a charm.
    Code:
        Set oPic = LoadPictureBytes(ByteBuffer)
    
    replaced with
    
        With New WIA.Vector
            .BinaryData = ByteBuffer
            Set oPic = .Picture
        End With
    and "wiaaut.dll" added to References. Now all the "png" files work.

    Thank You

    J.A. Coutts

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,070

    Re: Image Viewer

    Some finishing touches were added to PicView. The reason for producing this application was to overcome some of negative aspects of the Viewer that comes by default with Win 10. It is painfully slow at viewing pictures. The older Photo Viewer is still available if you are willing to update the registry, but that viewer also attempts to offer too much. I wanted a simple viewer that maximizes the available screen real estate.

    One advantage of using the same form size as the picture is that, should you need it, the print function becomes a very simple task (PrintForm).

    J.A. Coutts

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,070

    Re: Image Viewer

    The removal of the TaskBar on large images has been added. Depending of where you have located your TaskBar and the size of your screen, it would sometimes interfere with part of the image.

    J.A. Coutts

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,070

    Re: Image Viewer

    I have added the ability to use PicView as a default program by clicking on the associated file type. The hardest part was figuring out how to add PicView to the default programs in Win 10, now that MS has removed that ability from "Settings".

    Using the Windows Explorer, navigate to a file that you wish to activate using a different program that is not included in Win 10 default programs or MS store (eg. MyPicture.jpg). Right button click on it, and left button click on "Open with". Then click on "Choose another app". Now scroll down to the bottom and choose "More apps". Then scroll down to the bottom and choose "Look for another app on this PC". Navigate to the program you wish to use, and open it. The program will be added to your default programs. You can choose to use it for all the file types you have chosen now or later.

    The next task is to figure out how to prevent starting a new version of PicView for each picture file clicked on.

    J.A. Coutts

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,070

    Re: Image Viewer

    I have added the ability for PicView to recognize that a previous version of itself is already running and remove it. To recognize a previous version of itself, I used:
    Code:
        If App.PrevInstance Then
            TerminateProcess ("PicView.exe")
        End If
    The thing to note about this routine is that it does not work when in the IDE.

    To terminate the existing process, I found this routine:
    Code:
    Private Sub TerminateProcess(app_exe As String)
        Dim Process As Object
        For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = '" & app_exe & "'")
            Process.Terminate
        Next
    End Sub
    Unfortunately, this routine also killed the process that I was trying to load. The quick fix was to exit the loop after the first loop. There is probably a more efficient way to do this.

    J.A. Coutts

  8. #8
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    520

    Re: Image Viewer

    Quote Originally Posted by couttsj View Post
    Attached is a Picture Viewer. It does not have a bunch of fancy features, because the intent was to use as much of the screen as possible for the image itself. Inspiration for this program came from dilettante with his "Drop Send Pic".
    https://www.vbforums.com/showthread....mage-to-Base64
    Before anyone tells me that I could have just loaded the files directly into the Picture Box or the form Picture, I had difficulty in meeting the objectives doing it that way. I needed to not only adjust the container to suit the size of the image, but also to adjust the container for the size of the screen. I loaded the file into a byte array, and then I used a Picture Box because it was the only thing that would support "AutoRedraw". My intent is to eventually produce a remote Picture Viewer similar to dilettantes.

    J.A. Coutts

    Updated: 06/13/2021
    Updated: 06/20/2021
    Updated: 06/22/2021
    Updated: 06/24/2021
    Updated: 06/25/2021
    Code:
    Private Sub ResizePic(PicBox As PictureBox, oPic As Picture)
        Dim W As Single
        Dim H As Single
        Dim wAdj As Single
        Dim hAdj As Single
        Dim TBHide As Long
        TBHide = &H40 'Default to show TaskBar
        PicBox.Width = oPic.Width 'Adjust PicBox size
        PicBox.Height = oPic.Height 'to oPic size
       ? oPic is vbHimetric ; PicBox is PicBox.ScaleMode.why not ScaleX(oPic.Width, vbHimetric, PicBox.ScaleMode)
     
        'If picture larger than screen, adjust PicBox size & form location to upper left corner
        If oPic.Width > Screen.Width Then
       ?oPic.Width  why not  PicBox.width
            PicBox.Width = Screen.Width
            Me.Left = 0
            TBHide = &H80 'Hide TaskBar
        End If
        If oPic.Height > Screen.Height Then
            PicBox.Height = Screen.Height - BorderHeight
            Me.Top = 0
            TBHide = &H80 'Hide TaskBar
        End If
        'Get size of pBox in same scale mode as pPic
        W = PicBox.ScaleX(oPic.Width, vbHimetric, PicBox.ScaleMode)
        H = PicBox.ScaleY(oPic.Height, vbHimetric, PicBox.ScaleMode)
        'If image Width > pictureBox Width, resize Width
    
        If W > PicBox.ScaleWidth Then
            wAdj = PicBox.ScaleWidth / W
            W = PicBox.ScaleWidth
            H = H * wAdj 'Resize Height keeping proportions
        End If
        If H > PicBox.ScaleHeight Then
            hAdj = PicBox.ScaleHeight / H
            H = PicBox.ScaleHeight
            W = W * hAdj  'Resize Width keeping proportions
        End If
        PicBox.PaintPicture oPic, 0, 0, W, H
        Me.Width = W + BorderWidth
        Me.Height = H + BorderHeight
        Call TBAdjust(TBHide)
    End Sub
    Last edited by xxdoc123; Jul 16th, 2021 at 11:35 PM.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,070

    Re: Image Viewer

    Quote Originally Posted by xxdoc123 View Post
    Code:
        PicBox.Width = oPic.Width 'Adjust PicBox size
        PicBox.Height = oPic.Height 'to oPic size
       ? oPic is vbHimetric ; PicBox is PicBox.ScaleMode.why not ScaleX(oPic.Width, vbHimetric, PicBox.ScaleMode)
     
        'If picture larger than screen, adjust PicBox size & form location to upper left corner
        If oPic.Width > Screen.Width Then
       ?oPic.Width  why not  PicBox.width
    Is there a particular reason you would use those values instead. Graphics is not exactly my forte, so don't hesitate to provide the reasoning behind your suggestions.

    J.A. Coutts

Posting Permissions

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



Click Here to Expand Forum to Full Width