display image
display image
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
It's in the manual -> https://www.purebasic.com/documentation/image/
Re: display image
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?
It's a simple question, can you provide a simple example?
Re: display image
I linked to it in my other post...Sailor wrote: Wed Jan 12, 2022 10:06 pmIt's somewhere in there, but I can't find it. I've looked. Over & over.
Re: display image
There are examples inside Purebasic folder and the PB Help.
Show help ImageGadget and CanvasGadget
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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: display image
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
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
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.
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
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.
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
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.
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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: display image
I'm sorry if I offended you (it was not my intention), but I indicated the exact line where you have the error

Re: display image
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.
It's enough to get me started. I will have more stupid questions in the future.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: display image
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.
BERESHEIT
Re: display image
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..
- 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.
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
- 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.
- It was too lonely at the top.
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Re: display image
Just question.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
-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
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.
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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive