Sub AddLocationToImage(Dir As String, FileName As String, Latitude As Double, Longitude As Double)
Dim iv As ImageView
iv.Initialize("")
iv.Bitmap = LoadBitmap(Dir, FileName)
'The ImageView must have dimensions before initializing the Canvas.
iv.Width = iv.Bitmap.Width
iv.Height = iv.Bitmap.Height
Dim cvs As Canvas
cvs.Initialize(iv)
Dim LocationText As String
LocationText = NumberFormat2(Latitude, 1, 6, 6, False) & _
", " & NumberFormat2(Longitude, 1, 6, 6, False)
Dim TextSize As Float = 16
Dim LeftPosition As Float = 10dip
Dim BottomPosition As Float = iv.Height - 10dip
'Draw a black shadow slightly down and to the right.
cvs.DrawText(LocationText, _
LeftPosition + 1dip, _
BottomPosition + 1dip, _
Typeface.DEFAULT_BOLD, _
TextSize, _
Colors.Black, _
"LEFT")
'Draw the visible text over the shadow.
cvs.DrawText(LocationText, _
LeftPosition, _
BottomPosition, _
Typeface.DEFAULT_BOLD, _
TextSize, _
Colors.Yellow, _
"LEFT")
'Save the modified image.
Dim Out As OutputStream
Out = File.OpenOutput(Dir, FileName, False)
cvs.Bitmap.WriteToStream(Out, 90, "JPEG")
Out.Close
End Sub