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
Updated; 01/04/2025 - See Post #10 for details
Last edited by couttsj; Jan 4th, 2025 at 03:20 PM.
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
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.
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).
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.
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.
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.
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.
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.
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.
A very simple viewer. Easy project.
Your viewer does not support unicode file names with Chinese characters, the Chinese will cry. You'd be better off using W-functions...
Well, I think I figured out the reason. Not in API functions. The reason is in the dialogues. You need to abandon the control and switch to the API to open the file selection dialog. By the way, I have just such a simple module.
I decided to help you a little. I added the ability to drag and drop files with the mouse. I used the class module from our beloved fafalone user for this. Now, at least by dragging files with the mouse, files with Chinese characters will be displayed. At least that way.
I decided to help you a little. I added the ability to drag and drop files with the mouse. I used the class module from our beloved fafalone user for this. Now, at least by dragging files with the mouse, files with Chinese characters will be displayed. At least that way.
Thanks HackerVlad. It is not something I would have considered, but if it helps some users, then it is welcome. Personally, I could not get it to work. It tells me that OLEEXP is missing.
You're right, it's my mistake. The wrong link is written in the VBP file. I have attached the OLEGuids.tlb file and the link goes to another OLEEXP.tlb library. I'll try to solve it now.