Keeping canvas unchanged after orientation change?

ozgureffe

Member
Licensed User
Longtime User
I have a program containing a drawable canvas

I want my program to support both orientations, vertical and horizontal..

Everything seems Ok but when i rotate my device everything on my canvas becomes erased.

I tried saving canvas data on a file before rotation(Activity_Pause) , to read it again on canvas after rotation(Activity_Resume). But this method did't worked. It saved but only a blank file.

Maybe smth with Process_Globals or...

Where and how should I initialize canvas to protect its content even after rotation change?

Thank you for your help...
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Canvas is an activity object so cannot be declared in process_globals. How did you save and refresh it? It would be helpful if you could post some code.
 
Upvote 0

ozgureffe

Member
Licensed User
Longtime User
Thank you,

Actually i am sure my SaveTempImg and LoadTempImg Subs are working as they expected. Because when i assigned them on Click events, they do what I want.

But i dont know how can I build the logic of screen orientation changes...

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
    TmpMutableBmp.InitializeMutable(300dip,100dip)
    TmpMutableCanvas.Initialize2(TmpMutableBmp)
End Sub

----------------------------------

Sub Activity_Resume
    LoadTempImg
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    SaveTempImg
End Sub 

---------------------------------

Sub SaveTempImg
    Dim Out As OutputStream
    Out = File.OpenOutput(File.DirRootExternal, "/.SavedImg/temp.png" , False)
    TmpMutableBmp.WriteToStream(Out, 100, "PNG")
    Out.Close
End Sub

----------------------------
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I can't see from the code you've posted where you are displaying the bmp. It will save once you have drawn something on the canvas but as the canvas is not attached to a view, it won't display.

Your code is in the right place to save and retrieve the image, but we'd need to see more of your code to be able to tell why it's not re-displaying.

It would be helpful if you could build a small working test project that shows the problem and post that rather than code snippets, otherwise we have to build it ourselves to test it out.
 
Upvote 0
Top