Sub btnImage_Click
Dim phn As Phone
Dim fd As FileDialog
fd.FastScroll = True
fd.FilePath = File.DirRootExternal
fd.FileFilter = ".jpg,.png,.bmp,.gif"
ret = fd.Show("CHOOSE A BACKGROUND IMAGE", "Save", "Cancel", "", Null)
phn.HideKeyboard(Activity)
If ret = -1 Then
Dim bmp As Bitmap
Dim tmpAspectRatio As Float
Dim tmpLeft As Int :tmpLeft = 0
Dim tmpTop As Int :tmpTop = 0
Dim tmpWidth As Int :tmpWidth = Activity.Width
Dim tmpHeight As Int :tmpHeight = Activity.Height
StateManager.SetSetting("stgBackgroundPath", fd.FilePath)
StateManager.SetSetting("stgBackgroundName", fd.ChosenName)
bmp.Initialize(fd.FilePath,fd.ChosenName)
If (Activity.Width / Activity.Height) <> (bmp.Width / bmp.Height) Then
tmpAspectRatio = bmp.Width / bmp.Height
tmpHeight = Floor(Activity.Width / tmpAspectRatio)
If tmpHeight < Activity.Height Then
tmpHeight = Activity.Height
tmpWidth = Floor(Activity.Height * tmpAspectRatio)
End If
If tmpWidth > Activity.Width Then
tmpLeft = Floor((Activity.Width - tmpWidth) / 2)
End If
If tmpHeight > Activity.Height Then
tmpTop = Floor((Activity.Height - tmpHeight) / 2)
End If
End If
StateManager.SetSetting("stgBackgroundTop", tmpTop)
StateManager.SetSetting("stgBackgroundLeft", tmpLeft)
StateManager.SetSetting("stgBackgroundWidth", tmpWidth)
StateManager.SetSetting("stgBackgroundHeight", tmpHeight)
ToastMessageShow("Background Image : " & fd.FilePath & "/" & fd.ChosenName, False)
End If
End Sub