Page 1 of 2

display image

Posted: Wed Jan 12, 2022 9:02 pm
by Sailor
I'm very new to this language. For right now, all I want to do is load an image and display it. I can't find a topic that is this rudimentary, so ... help?

Re: display image

Posted: Wed Jan 12, 2022 9:53 pm
by BarryG
Sailor wrote: Wed Jan 12, 2022 9:02 pmI can't find a topic that is this rudimentary
It's in the manual -> https://www.purebasic.com/documentation/image/

Re: display image

Posted: Wed Jan 12, 2022 10:06 pm
by Sailor
It's somewhere in there, but I can't find it. I've looked. Over & over.
It's a simple question, can you provide a simple example?

Re: display image

Posted: Wed Jan 12, 2022 10:13 pm
by BarryG
Sailor wrote: Wed Jan 12, 2022 10:06 pmIt's somewhere in there, but I can't find it. I've looked. Over & over.
I linked to it in my other post...

Re: display image

Posted: Wed Jan 12, 2022 10:21 pm
by mk-soft
There are examples inside Purebasic folder and the PB Help.

Show help ImageGadget and CanvasGadget

Code: Select all


CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  imagefile.s = #PB_Compiler_Home + "examples\sources\Data\PureBasic.bmp"
CompilerElse
  imagefile.s = #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp"
CompilerEndIf  

If OpenWindow(0, 0, 0, 500, 300, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If LoadImage(0, imagefile)    ; change 2nd parameter to the path/filename of your image
    ImageGadget(0,  10, 10, 400, 100, ImageID(0))                      ; imagegadget standard
    ImageGadget(1, 10, 100, 400, 100, ImageID(0), #PB_Image_Border)    ; imagegadget with border
  EndIf
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: display image

Posted: Wed Jan 12, 2022 10:34 pm
by Sailor
blank window.
What did I do wrong?
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
imagefile.s = #PB_Compiler_Home + "examples\sources\Data\PureBasic.bmp"
CompilerElse
imagefile.s = #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp"
CompilerEndIf
If OpenWindow(0, 0, 0, 500, 300, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If LoadImage(0, "examples\sources\Data\PureBasic.bmp") ; change 2nd parameter to the path/filename of your image
ImageGadget(0, 10, 10, 400, 100, ImageID(0)) ; imagegadget standard
ImageGadget(1, 10, 100, 400, 100, ImageID(0), #PB_Image_Border) ; imagegadget with border
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: display image

Posted: Wed Jan 12, 2022 10:50 pm
by Caronte3D
Do you know how to code works?
You must understand what you're doing.
If you compile the source EXACTLY like mk-soft posted, you will see the images.
You get black screen because you modified wrong the LoadImage line.

Re: display image

Posted: Wed Jan 12, 2022 11:00 pm
by Sailor
Excuse me, I've been writing code my whole adult life, the last 20 years I've spent coding with MATLAB processing retinal images that led to 32 peer reviewed papers and 2 patents.

The code I posted was EXACTLY what the replier posted. It didn't work, I got a white screen. I didn't change a single line.

Normally, IME, people are helpful to newbies.

Re: display image

Posted: Wed Jan 12, 2022 11:19 pm
by mk-soft
Of course we help newbies here

But you have changed the path to the image and no longer use the string variable to the image.
The string constant #PB_Compiler_Home is already part of the path to the image.

Code: Select all

Debug #PB_Compiler_Home

Re: display image

Posted: Wed Jan 12, 2022 11:24 pm
by Caronte3D
Sailor wrote: Wed Jan 12, 2022 11:00 pm Normally, IME, people are helpful to newbies.
I'm sorry if I offended you (it was not my intention), but I indicated the exact line where you have the error :wink:

Re: display image

Posted: Wed Jan 12, 2022 11:50 pm
by Sailor
Thanks all, I get part of it, know what I was doing wrong, and made it work.
It's enough to get me started. I will have more stupid questions in the future.

Re: display image

Posted: Thu Jan 13, 2022 12:41 am
by netmaestro
Welcome aboard and bring the questions on! Don't worry that they're rudimentary, there is no such thing as a stupid question. And a good many of us in checking out the answers to simple questions find that there are better ways to be doing things they've done for years. Me included. So welcome and have fun with the language, I just know you'll get hooked on it.

Re: display image

Posted: Thu Jan 13, 2022 2:18 pm
by blueb
A few hints to guide you...

when you wish to download code 'from' the forum:
- go to the top right corner of the sample.
- a hidden 'copy' button will appear
- click on it and it will place all the code on the clipboard.
- simply Ctrl-V this code into the PB IDE
this method will be fast and accurate. :)

When you 'paste code' into the forum..
Use the "code /code" tags.
It makes it easier to read, and copy into the viewers program.
There's a '</>' button to help you.
-----------------

Regarding the sample that mk-soft provided...

Once you've got this code into your program:

If things don't work (or you're curious) and you needed more info about the LoadImage() command..

Code: Select all

  If LoadImage(0, imagefile)    ; change 2nd parameter to the path/filename of your image
    ImageGadget(0,  10, 10, 400, 100, ImageID(0))                      ; imagegadget standard
    ImageGadget(1, 10, 100, 400, 100, ImageID(0), #PB_Image_Border)    ; imagegadget with border
  EndIf
- place your cursor anywhere in the LoadImage() text
- press the 'F1' key and PureBasic will open the help file on this command.

In this case, Help explains 'what' went wrong...

Filename$ = The name of the file to load. If the filename does not include a full path, it is interpreted relative to the current directory.

As you can see, your sample only provided a partial path... not the full path.... hence the error.

Welcome to the community.

Re: display image

Posted: Mon Sep 25, 2023 12:29 pm
by Attronach
mk-soft wrote: Wed Jan 12, 2022 10:21 pm There are examples inside Purebasic folder and the PB Help.

Show help ImageGadget and CanvasGadget

Code: Select all

If OpenWindow(0, 0, 0, 500, 300, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If LoadImage(0, imagefile)    ; change 2nd parameter to the path/filename of your image
    ImageGadget(0,  10, 10, 400, 100, ImageID(0))                      ; imagegadget standard
    ImageGadget(1, 10, 100, 400, 100, ImageID(0), #PB_Image_Border)    ; imagegadget with border
  EndIf
EndIf
Just question.

-running main program in console mode (text outputs, keyboard input)
-show image in new window (using your sample code)

Everything work fine BUT ... how I can transfer status 'active window' back to main program?
ATM I have to mouseclick to main window and then I can continue with program (handle input key and then use CloseWindow(0))

Any idea?

Re: display image

Posted: Mon Sep 25, 2023 1:25 pm
by mk-soft
Why Console,

Mixing GUI and Console is not useful. Otherwise, Console and Window of the focus must always be changed with the mouse. In addition, the user input does not work in the GUI part and comes to errors, because here also all events must be processed.