I know you are talking about Graphics, but if you need to resize the Picture image and, optionally, keep it both proportional to the original and/or centre it in the frame:
[code]Protected Function getResizePictureWAD(myPicture As Picture, areaWidth As Integer, areaHeight As Integer, isProportional As Boolean = True, isCentrePicture As Boolean = True) as Picture
Dim tempPicture As Picture
Dim Ratio As Double
If myPicture = Nil Then
Return Nil
End If
If areaWidth < 1 Or areaHeight < 1 Then
Return Nil
End If
Ratio = myPicture.width / myPicture.height
If isProportional And Ratio <> 1 Then
If myPicture.Width > myPicture.Height Then
tempPicture = New Picture(areaWidth, areaHeight)
If isCentrePicture Then
Var NewHeight As Double = areaHeight * (myPicture.height / myPicture.width)
Var NewTop As Double = (areaHeight - (NewHeight)) / 2
tempPicture.Graphics.DrawPicture(myPicture, 0, NewTop, areaWidth, NewHeight, 0, 0, myPicture.Width, myPicture.Height)
Else
tempPicture.Graphics.DrawPicture(myPicture, 0, 0, areaWidth, areaWidth / Ratio, 0, 0, myPicture.Width, myPicture.Height)
End If
Else
tempPicture = New Picture(areaWidth, areaHeight)
If isCentrePicture Then
Var NewWidth As Double = areaWidth * (myPicture.Width / myPicture.Height)
Var NewLeft As Double = (areaWidth - (NewWidth)) / 2
tempPicture.Graphics.DrawPicture(myPicture, NewLeft, 0, NewWidth, areaHeight, 0, 0, myPicture.Width, myPicture.Height)
Else
tempPicture.Graphics.DrawPicture(myPicture, 0, 0, areaHeight * Ratio, areaHeight, 0, 0, myPicture.Width, myPicture.Height)
End If
End If
Else
tempPicture = New Picture(areaWidth, areaHeight)
tempPicture.Graphics.DrawPicture(myPicture, 0, 0, areaWidth, areaHeight, 0, 0, myPicture.Width, myPicture.Height)
End If
Return tempPicture
End Function[/code]