Option Explicit
Private Sub Command1_Click()
Dim pTempPicture As IPictureDisp
Dim nWidth As Integer
Dim nHeight As Integer
Dim nTop As Integer
Dim nLeft As Integer
Dim dScaleFactor As Double
Rem ===================================================
Rem == Das Bild in den Speicher holen. ==
Rem ===================================================
Set pTempPicture = LoadPicture("Dein_Bild_auf_der_Platte.jpg")
Rem ===================================================
Rem == IPictureDisp gibt die Höhe und Breite in ==
Rem == Himetric an. Umwandeln in Pixel. ==
Rem ===================================================
Picture1.ScaleMode = vbPixels
nWidth = ScaleX(pTempPicture.Width, vbHimetric, vbPixels)
nHeight = ScaleY(pTempPicture.Height, vbHimetric, vbPixels)
Rem ===================================================
Rem == Über welche Achse muss skaliert werden? ==
Rem ===================================================
With Picture1
If (nWidth - .ScaleWidth) > (nHeight - .ScaleHeight) Then
dScaleFactor = .ScaleWidth / nWidth
Else
dScaleFactor = .ScaleHeight / nHeight
End If
Rem ===============================================
Rem == Das Bild nun auf die Picturebox bringen. ==
Rem ===============================================
.Picture = LoadPicture()
.Cls
nWidth = nWidth * dScaleFactor
nHeight = nHeight * dScaleFactor
nTop = (.ScaleHeight - nHeight) / 2
nLeft = (.ScaleWidth - nWidth) / 2
Picture1.PaintPicture pTempPicture, nLeft, nTop, nWidth, nHeight
End With
Rem ===================================================
Rem == Ein bischen Müll beseitigen. ==
Rem ===================================================
Set pTempPicture = LoadPicture()
Set pTempPicture = Nothing
End Sub