How do you load many bmp's in PageTurnView?

varbello

Member
Licensed User
Longtime User
It seems that if you do not call Pager.Paginate(text) you can only get 2,3 images . How can i load many bmp's without any text ?
I have posted the following code which works (all bmp's shown) , only if you call Pager.Paginate(text)
I want to load , say 30 bmp's, with no text, how??
can someone paste some code.. Thanks !



B4X:
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
   
Dim bmp As Bitmap
    Dim cover As Bitmap
    Dim cnv As Canvas
    bmp.InitializeMutable(Width, Height) ' do this here so we have a valid return in 
        If Page = 0 Then
         cover=LoadBitmap(File.DirAssets, "image3.jpg")
           Dim DestRect As Rect
            DestRect.Initialize(0dip, 0dip,Width, Height) 
            cnv.Initialize2(bmp)
            cnv.DrawBitmap (cover, Null, DestRect)
            Return bmp
       Else If  Page = 1 Then
          cover.Initialize(File.DirAssets, "1.jpg")
            cnv.Initialize2(bmp)
            Dim DestRect As Rect
            DestRect.Initialize(0dip, 0dip,Width, Height) 
            cnv.DrawBitmap (cover, Null, DestRect)
            Return bmp   
       Else If  Page = 2 Then
       cover.Initialize(File.DirAssets, "2.jpg")
            cnv.Initialize2(bmp)
            Dim DestRect As Rect
            DestRect.Initialize(0dip, 0dip,Width, Height) 
            cnv.DrawBitmap (cover, Null, DestRect)
            Return bmp
       Else If Page = 3 Then
          cover.Initialize(File.DirAssets, "3.jpg")
            cnv.Initialize2(bmp)
            Dim DestRect As Rect
            DestRect.Initialize(0dip, 0dip,Width, Height) 
            cnv.DrawBitmap (cover, Null, DestRect)
            Return bmp
        Else If  Page = 4 Then
      cover.Initialize(File.DirAssets, "4.jpg")
            cnv.Initialize2(bmp)
            Dim DestRect As Rect
            DestRect.Initialize(0dip, 0dip,Width, Height) 
            cnv.DrawBitmap (cover, Null, DestRect)
           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.White)
      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
 

Beja

Expert
Licensed User
Longtime User
B4X:
If Page = 0 Then
        cover=LoadBitmap(File.DirAssets, "image3.jpg")
          Dim DestRect As Rect
            DestRect.Initialize(0dip, 0dip,Width, Height)
            cnv.Initialize2(bmp)
            cnv.DrawBitmap (cover, Null, DestRect)
            Return bmp
      Else If  Page = 1 Then
          cover.Initialize(File.DirAssets, "1.jpg")
            cnv.Initialize2(bmp)
            Dim DestRect As Rect
            DestRect.Initialize(0dip, 0dip,Width, Height)
            cnv.DrawBitmap (cover, Null, DestRect)
            Return bmp 
      Else If  Page = 2 Then
      cover.Initialize(File.DirAssets, "2.jpg")
            cnv.Initialize2(bmp)
            Dim DestRect As Rect
            DestRect.Initialize(0dip, 0dip,Width, Height)
            cnv.DrawBitmap (cover, Null, DestRect)
            Return bmp
      Else If Page = 3 Then
          cover.Initialize(File.DirAssets, "3.jpg")

Hi,
I see you are using the image name is the same as the page number.. don't you think in this case it is better that
you use a for-next LOOP?

B4X:
FOR x = 0 to NumberOfPages - 1
            DIM cBmp as string = x & ".jpg"
            cover.Initialize(File.DirAssets, cBmp)
            cnv.Initialize2(bmp)
            Dim DestRect As Rect
            DestRect.Initialize(0dip, 0dip,Width, Height)
            cnv.DrawBitmap (cover, Null, DestRect)
            Return bmp
NEXT x

I didn't test it though
 
Upvote 0
Top