If it helps… Here’s what I currently use to resize images, it allows for fitting, filling (with cropping) and stretching. Also importantly you can prevent small images from resized up, which I needed for something.
[code]Public Function resizeToFit(extends p as picture, maxWidth as integer, maxHeight as integer, scaleMode as pictureScaleMode = pictureScaleMode.toFit, onlyShrink as boolean = false) as picture
Dim nSize as xojo.core.size
select case scaleMode
case picturescaleMode.toFit, picturescaleMode.toFill // – Scale to fit & Scale to fill
dim scale as Double = if( scaleMode = picturescaleMode.toFit, _
min( maxHeight / p.height, maxWidth / p.width ), _
max( maxHeight / p.height, maxWidth / p.width ) )
if onlyShrink then scale = min( scale, 1.0 )
nSize = new xojo.core.size( floor( p.width * scale ), floor( p.height * scale ) )
case picturescaleMode.stretchToFill // — Stretch to fill.
nSize = new xojo.Core.size( maxWidth, maxHeight )
end select
// — Now create the target image and draw our image into the center.
Dim rvalue as new picture( min( nSize.width, maxWidth ), min( nSize.height, maxHeight ) )
rvalue.graphics.drawPicture( p, ( rvalue.width - nSize.width ) * 0.5, ( rvalue.height - nSize.height ) * 0.5, _
nSize.width, nSize.height, 0, 0, p.width, p.height )
return rvalue
End Function
[/code]
You also need the enum
Public Enum pictureScaleMode
toFit
toFill
stretchToFill
End Enum