Sub Globals
Private ImageView1, ImageView2, ImageView3, ImageView4 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
FitCenterBitmap(ImageView1, File.DirAssets, "rose2.jpg", 1)
FitCenterBitmap(ImageView2, File.DirAssets, "rose2.jpg", 1)
FitCenterBitmap(ImageView3, File.DirAssets, "rose2.jpg", 2)
FitCenterBitmap(ImageView4, File.DirAssets, "rose2.jpg", 2)
End Sub
Sub FitCenterBitmap(Imv As ImageView, Dir As String, FileName As String, Mode As Int)
Private bmp As Bitmap = LoadBitmap(Dir, FileName)
Private cvs As Canvas
cvs.Initialize(Imv)
Dim rectDest, rectSource As Rect
Dim delta As Int
Select Mode
Case 1
If bmp.Width / bmp.Height > Imv.Width / Imv.Height Then
delta = (Imv.Height - bmp.Height / bmp.Width * Imv.Width) / 2
rectDest.Initialize(0, delta,Imv.Width, Imv.Height - delta)
Else
delta = (Imv.Width - bmp.Width / bmp.Height * Imv.Height) / 2
rectDest.Initialize(delta, 0, Imv.Width - delta, Imv.Height)
End If
cvs.DrawBitmap(bmp, Null, rectDest)
Case 2
rectDest.Initialize(0, 0,Imv.Width, Imv.Height)
If bmp.Width / bmp.Height > Imv.Width / Imv.Height Then
delta = (bmp.Width - Imv.Width / Imv.Height * bmp.Height) / 2
rectSource.Initialize(delta, 0,bmp.Width - delta, bmp.Height)
Else
delta = (bmp.Height - Imv.Height / Imv.Width * bmp.Width) / 2
rectSource.Initialize(0, delta, bmp.Width, bmp.Height - delta)
End If
cvs.DrawBitmap(bmp, rectSource, rectDest)
End Select
Imv.Invalidate
End Sub