Sub PageTurner_GetBitmap(Width As Int, Height As Int, Page As Int) As Bitmap 'Called when the Bitmap for the given page number is required. Return the Bitmap
' As this is running on a separate thread exceptions will cause the application to force close
' and not report the exception as would happen on the main thread so we use a Try Catch block
' to trap any errors
Dim bmp As Bitmap
Dim cnv As Canvas
bmp.InitializeMutable(Width, Height) ' do this here so we have a valid return in case of an exception
Try
'File.OpenInput("bad", "filename") ' this would cause an exception to be reported on the main thread
If Page = 0 Then
cnv.Initialize2(bmp)
cnv.DrawColor(Colors.Blue)
cnv.DrawText( "A Book", Width/2, 100dip, Typeface.DEFAULT, 24, Colors.White, "CENTER")
Return bmp
Else If Page = Pager.PageCount + 1 Then
cnv.Initialize2(bmp)
cnv.DrawColor(Colors.DarkGray)
cnv.DrawText( "The End", Width/2, 100dip, Typeface.DEFAULT, 24, Colors.White, "CENTER")
Return bmp
Else
' Return Pager.GetPageBitmap(Page - 1, Colors.Yellow)
bmp = LoadBitmapSample(File.DirAssets, "Imagine.jpg", Width, Height)
Return bmp
End If
Catch
' catch and report any exceptions on the rendering thread to the main thread
PTException
End Try
Return bmp ' if we don't return something valid we will cause an exception on the rendering thread
End Sub