Just starting out? Need help? Post your questions and find answers here.
Stefan
 
Posts: 8
Joined: Mon Feb 05, 2018 9:44 pm

Loading a picure on the fly

by Stefan Sat Feb 10, 2018 10:03 am

Is there a possibility to load pictures on the fly?
At the moment I know only code to load images at program start.
Alexander
 
Posts: 4
Joined: Wed Feb 07, 2018 10:34 am

Re: Loading a picure on the fly

by Alexander Sun Feb 11, 2018 10:52 am

Hello Stefan, something like this:
Code: Select all
Procedure Loaded(Type, Filename$, ObjectId)
  Debug "Loading image: " + Filename$
EndProcedure

Procedure LoadingError(Type, Filename$, ObjectId)
  Debug Filename$ + ": loading error"
EndProcedure

BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())

OpenWindow(0, 0, 0, 320, 200, "Image", #PB_Window_ScreenCentered)
CanvasGadget(1, 10, 10, 180, 180)
ButtonGadget(2, 220, 20, 80, 20, "Load image 1")
ButtonGadget(3, 220, 50, 80, 20, "Load image 2")
ButtonGadget(4, 220, 100, 80, 20, "View image 1")
ButtonGadget(5, 220, 130, 80, 20, "View image 2")

Procedure GadgetEvent()
  Select EventGadget()
    Case 2
      LoadImage(11, "https://www.spiderbasic.com/img/logo.png")
    Case 3
      LoadImage(12, "http://forums.spiderbasic.com/styles/anami/imageset/spiderbasic.png")
    Case 4
      StartDrawing(CanvasOutput(1))
      DrawImage(ImageID(11), 0, 0)
      StopDrawing()
    Case 5
      StartDrawing(CanvasOutput(1))
      DrawImage(ImageID(12), 0, 50)
      StopDrawing()
  EndSelect
EndProcedure

BindEvent(#PB_Event_Gadget, @GadgetEvent())
Stefan
 
Posts: 8
Joined: Mon Feb 05, 2018 9:44 pm

Re: Loading a picure on the fly

by Stefan Sun Feb 11, 2018 11:49 am

The problem here is, you need two steps to show a picture.
Step 1 to push a button to load a picture and
Step 2 to show this picture.

I need a way to do this in 1 step, to load a picture and to show it immediately without any more steps.
Alexander
 
Posts: 4
Joined: Wed Feb 07, 2018 10:34 am

Re: Loading a picure on the fly

by Alexander Sun Feb 11, 2018 12:28 pm

Use timer.
Dirk Geppert
 
Posts: 45
Joined: Fri Sep 22, 2017 7:02 am

Re: Loading a picure on the fly

by Dirk Geppert Mon Feb 12, 2018 9:52 am

Code: Select all
Procedure Loaded(Type, Filename$, ObjectId)
  Select ObjectId
    Case 11     
      StartDrawing(CanvasOutput(1))
      DrawImage(ImageID(11), 0, 0)
      StopDrawing()
    Case 12
      StartDrawing(CanvasOutput(1))
      DrawImage(ImageID(12), 0, 50)
      StopDrawing()
  EndSelect
EndProcedure

Procedure LoadingError(Type, Filename$, ObjectId)
  Debug Filename$ + ": loading error"
EndProcedure

BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())

OpenWindow(0, 0, 0, 320, 200, "Image", #PB_Window_ScreenCentered)
CanvasGadget(1, 10, 10, 180, 180)
ButtonGadget(2, 220, 20, 80, 20, "Load image 1")
ButtonGadget(3, 220, 50, 80, 20, "Load image 2")

Procedure GadgetEvent()
  Select EventGadget()
    Case 2
      LoadImage(11, "https://www.spiderbasic.com/img/logo.png")
    Case 3
      LoadImage(12, "http://forums.spiderbasic.com/styles/anami/imageset/spiderbasic.png")

  EndSelect
EndProcedure

BindEvent(#PB_Event_Gadget, @GadgetEvent())
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 4 guests