Bitmap Value Lost?

fjsantos

Member
Licensed User
Hi all.

I finally buy this wonderfull app.
Now i have more doubts than ever!

I have problems using imagelib library.
The problem is the following, when i create a bitmap with backdrop image, I create a drawer and paint a bit image over previous, using drawer.drawimage1
When I first time, try to draw in a gamewindow.drawbackgroundimage2, all seems to be correct, but the second time, value doesn't work.
I have to use an intermediate image for storing value of backdropbitmap and reassign every time.

The code is follow.

B4X:
Sub UpdateForm(x, y)
   CellBitmap.New1(AppPath & "\images\cell.png")
   'BackdropBitmap.New3(TmpBackdropBitmap.Value)
   CellRectangle.New1(0, 0, CellBitmap.Width, CellBitmap.Height)
   BackdropRectangle.New1(x, y, CellBitmap.Width, CellBitmap.Height)
   GameFormDrawer.New2(BackdropBitmap.Value, B4PObject(5))
   GameFormDrawer.DrawImage1(CellBitmap.Value, CellRectangle.Value, BackdropRectangle.Value, false)
   GameFormDrawer.Refresh2(BackdropRectangle.Value)
   'TmpBackdropBitmap.New3(BackdropBitmap.Value)
   GameGameWindow.DrawBackgroundImage2(BackdropBitmap.Value)
End Sub

This methods seems to work, but i wonder why i have to create new BackdropBitmap referencing to previous (TmpBackdropBitmap).

I commented 2 lines needed to work, and i wonder why I need this 2 lines.

Any Clues?

Thanks in advance.

fjsantos.
________
XVZ1300
 
Last edited:

fjsantos

Member
Licensed User
Hi Klaus

Thanks for helping.

Code is a bit large so I extract important part.

B4X:
Sub App_Start
   GameFormLib.New1("GameForm", B4PObject(1))
   GameGameWindow.New1("GameForm", 0, 0, WIDTH, HEIGHT)
   GameGameWindow.DrawBackgroundImage(AppPath & "\images\backdrop.png")
   ObjectDoor.New1(False)
   ObjectDoor.FromControl("GameForm")
   ObjectDoor.SetProperty("KeyPreview", True)
   TmpBackdropBitmap.New1(AppPath & "\images\backdrop.png")
   GameForm.Image = TmpBackdropBitmap.Value
   GameForm.Show
   GameForm.ForeLayer = True
   CreateCloseButton
   CreateNewCell
   UpdateForm1
   MoveCellTimer.Enabled = True
End Sub

Sub UpdateForm1
   CellBitmap.New1(AppPath & "\images\cell.png")
   CellRectangle.New1(0, 0, CellBitmap.Width, CellBitmap.Height)
   BackdropRectangle.New1(0, 0, CellBitmap.Width, CellBitmap.Height)
   GameFormDrawer.New1("GameForm", True)
End Sub

Sub UpdateForm(x, y)
   BackdropRectangle.X = x
   BackdropRectangle.Y = y
   GameFormDrawer.DrawImage1(CellBitmap.Value, CellRectangle.Value, BackdropRectangle.Value, False)
   GameFormDrawer.Refresh2(BackdropRectangle.Value)
   GameGameWindow.DrawBackgroundImage2(GameForm.Image)
End Sub

The first time GameGameWindow draws GameForm.Image all seems to be ok, but the second one, its fails 'Parameter is not valid'.

Thanks, fjsantos.
________
DR-Z400
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the same problem as this one: http://www.b4x.com/forum/questions-help-needed/1852-fullscreen-problem.html
DrawBackgroundImage2 disposes the image after drawing it on the GameWindow.

The solution is to create a new copy of the image (with a Bitmap object) and then pass it.
It will be fixed in the next update of the Sprite library.

BTW, why are you setting ForeLayer to true? It is hidden by the GameWindow.
There is a problem with the designer code in your source file.
You can use the attached file instead.
 

fjsantos

Member
Licensed User
Hi all.

Yep i suppose that image was disposing after drawimage. The code was only a draft playing around with forms and gamewindows (I have to learn a lot yet!).

Thanks a lot for improve the code!!

Klaus thanks to you too for your interest and help!!

Best Regards, fjsantos.
________
weed news
 
Last edited:
Top