Android Question PageTurnVew, image page blank.

Beja

Expert
Licensed User
Longtime User
Hi,
using agraham's pageturnview, I have the code provided in the example and edit it to show an image
instead of text. But the page is blank.
B4X:
            If Page = 0 Then       
            Dim Bitmap1 As Bitmap
            Bitmap1.initialize(File.DirAssets, "1.jpg")
            Dim DestRect As Rect
            DestRect.Initialize(10dip, 10dip, Activity.Width - 20dip, Activity.Height - 20dip)
            cnv.drawbitmap( Bitmap1, Null, DestRect)
            Return bmp
Someone point me where the bug is when I changed the original code.

Thanks in advance.
 

LucaMs

Expert
Licensed User
Longtime User
Hi,
using agraham's pageturnview, I have the code provided in the example and edit it to show an image
instead of text. But the page is blank.
B4X:
            If Page = 0 Then      
            Dim Bitmap1 As Bitmap
            Bitmap1.initialize(File.DirAssets, "1.jpg")
            Dim DestRect As Rect
            DestRect.Initialize(10dip, 10dip, Activity.Width - 20dip, Activity.Height - 20dip)
            cnv.drawbitmap( Bitmap1, Null, DestRect)
            Return bmp
Someone point me where the bug is when I changed the original code.

Thanks in advance.


I have only done this test, it works but of course you should then be able to change images:

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
    ' 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
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thank you so much...

using your code:
1- the pages are all filled with the image "x.jpg", except of course the first and the last.
2- the image is not resized to the canvas automatically and only the top-letf part was displayed, cutting the right
and bottom that was outside of the canvas area.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Thank you so much...

using your code:
1- the pages are all filled with the image "x.jpg", except of course the first and the last.
2- the image is not resized to the canvas automatically and only the top-letf part was displayed, cutting the right
and bottom that was outside of the canvas area.

I said you... i made only a "fly" try, I have not studied the code, that was only an indication :)
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thanks.. at this time I want to auto-resize the image to fit into the canvas..

One thing I need to test:
Is page = 3 the same as page = Pager.PageCount - 2? (assuming pagecount is from 0 to 4 = 5)
 
Upvote 0
Top