Sub ResizeImage(original As Bitmap, TargetX As Int, TargetY As Int) As Bitmap
Dim origRatio As Float = original.Width / original.Height
Dim targetRatio As Float = TargetX / TargetY
Dim scale As Float
If targetRatio > origRatio Then
scale = TargetY / original.Height
Else
scale = TargetX / original.Width
End If
Dim c As Canvas
Dim b As Bitmap
b.InitializeMutable(TargetX, TargetY)
c.Initialize2(b)
'set the background
c.DrawColor(Colors.LightGray)
Dim r As Rect
Dim w = original.Width * scale, h = original.Height * scale As Int
r.Initialize(TargetX / 2 - w / 2, TargetY / 2 - h / 2, TargetX / 2 + w / 2, TargetY / 2+ h / 2)
Dim ExtDraw As ABExtDrawing
Dim paint As ABPaint
paint.Initialize()
paint.setFilterBitmap(True)
paint.SetAntiAlias(True)
ExtDraw.drawBitmap(C, original, Null, R, paint)
return b
End Sub