
Originally Posted by
couttsj
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