dim imgBackground as ImageView
sub Show
...........
MainForm.Show
Dim bmp As B4XBitmap = xui.LoadBitmap(File.DirAssets, "EventBackGround-PalmSprings.jpg")
FillImageToView(bmp, imgBackground)
end sub
Sub FillImageToView(bmp As B4XBitmap, ImageView As B4XView)
Dim bmpRatio As Float = bmp.Width / bmp.Height
Dim viewRatio As Float = ImageView.Width / ImageView.Height
If viewRatio > bmpRatio Then
Dim NewHeight As Int = bmp.Width / viewRatio
bmp = bmp.Crop(0, bmp.Height / 2 - NewHeight / 2, bmp.Width, NewHeight)
Else if viewRatio < bmpRatio Then
Dim NewWidth As Int = bmp.Height * viewRatio
bmp = bmp.Crop(bmp.Width / 2 - NewWidth / 2, 0, NewWidth, bmp.Height)
End If
Dim scale As Float = 1
ImageView.SetBitmap(bmp.Resize(ImageView.Width * scale, ImageView.Height * scale, True))
End Sub