Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

FAQ.How to scale a picture proportionally with mask?
Answer: For a proportional scaling, we calculate the new picture size relative to the target maximum size.
Function ProportinalScaledWithMask(extends pic as Picture, Width as Integer, Height as Integer) As Picture
// Calculate scale factor

dim faktor as Double = min( Height / Pic.Height, Width / Pic.Width)

// Calculate new size
dim w as Integer = Pic.Width * faktor
dim h as Integer = Pic.Height * faktor

// create new picture
dim NewPic as new Picture(w,h,32)

// check if we have a mask and clear it
dim m as picture = pic.mask(False)
pic.mask = nil

// draw picture in the new size
NewPic.Graphics.DrawPicture Pic, 0, 0, w, h, 0, 0, Pic.Width, Pic.Height

if m <> nil then
// restore mask and scale it
pic.mask = m
NewPic.mask.Graphics.DrawPicture m, 0, 0, w, h, 0, 0, Pic.Width, Pic.Height
end if

// return result
Return NewPic
End Function
Notes: This version handles mask. As you see we actually have to remove mask in order to copy the picture part correctly.

Feedback, Comments & Corrections

The biggest plugin in space...

MBS Xojo PDF Plugins