# Scaling a Photo in a Canvas

I need help Scaling a Picture in a Canvas. There’s is no exact size of the photo I am uploading because the user is uploading the photo themselves then it will scale to the size of the canvas which is (640x480). When they upload the photo it is basically focusing on just one part of the photo when it should be the whole photo but scaled down. Thank you

In the Canvas Paint event

g.drawPicture myPic, 0, 0, me.width, me.height, 0, 0, myPic.Width, myPic.Height

where myPic is your camera picture.

This might be of interest to you

This will work as is if the aspect ratio of your pic is the same as the ratio of the canvas. Otherwise, see Albin’s link for aspect scaling

Here is an Example

[code] // draw rectangle to see the area of the canvas
// g.ForeColor= &c000000 black
g.ForeColor= &cFF0000 // red
g.DrawRect 0,0,Me.width,Me.height

// -------------------------------------------------------
// scale picture keeping the ratio between x and y
// -------------------------------------------------------
if myPic <> nil then

``````dim CanvasWidth, CanvasHeight, PicWidth, PicHeight, ScaleWidth, ScaleHeight as int16
dim RatioX, RatioY,PosX, PosY as double

CanvasWidth = me.width
CanvasHeight = me.Height
PicWidth = myPic.Width
PicHeight = myPic.Height
RatioX = CanvasWidth / PicWidth
RatioY = CanvasHeight / PicHeight

if RatioY < RatioX then
ScaleWidth = PicWidth * RatioY
ScaleHeight = PicHeight * RatioY
PosX = ((CanvasWidth - ScaleWidth)/2) + 10
PosY = 10
else
ScaleWidth = PicWidth * RatioX
ScaleHeight = PicHeight * RatioX
PosX = 10
PosY = ((CanvasHeight - ScaleHeight)/2) + 10
end if
g.DrawPicture(myPic,PosX, PosY, ScaleWidth - 20, ScaleHeight - 20, 0, 0, PicWidth, PicHeight)

[/code]``````

Forgot to tell that above code goes in Canvas Paint event