Sub PageTurner_GetBitmap(Width As Int, Height As Int, Page As Int) As Bitmap
Dim bmp As Bitmap
Dim can As Canvas
' do this here so we have a valid return in case of an exception
bmp.InitializeMutable(Width, Height)
' if on page 0 create the "Start" page
If Page=0 Then
can.Initialize2(bmp) : can.DrawColor(Colors.DarkGray)
can.DrawText("Turn Page for Help", Width/2, Height/3, Typeface.DEFAULT, 24, Colors.White, "CENTER")
Return bmp
End If
' if past the end of the pages create the "End" page
If Page>NUMPAGES Then
can.Initialize2(bmp) : can.DrawColor(Colors.DarkGray)
can.DrawText( "End", Width/2, Height/3, Typeface.DEFAULT, 24, Colors.White, "CENTER")
Return bmp
End If
' load the image for the page
Try
can.Initialize2(bmp) : can.DrawColor(Colors.Black)
Dim thisBitmap As Bitmap = LoadBitmap(File.DirAssets, Page & ".png")
Dim dst As Rect : dst.Initialize(0,0,thisBitmap.Width,thisBitmap.Height)
' scale the image to fit on the page
Dim aspect As Float = thisBitmap.Width/thisBitmap.Height
If dst.Right>Width Or dst.Bottom<Height Then
dst.Right=Width : dst.Bottom=Floor(dst.Right/aspect)
End If
If dst.Bottom>Height Or dst.Right<Width Then
dst.Bottom=Height : dst.Right=Floor(dst.Bottom*aspect)
End If
can.DrawBitmap(thisBitmap,Null,dst)
Return bmp
Catch
' catch and report any exceptions on the rendering thread to the main thread
PTException
End Try
' return something to avoid causing an exception on the rendering thread
Return bmp
End Sub