display image

Just starting out? Need help? Post your questions and find answers here.
Sailor
New User
New User
Posts: 5
Joined: Wed Jan 12, 2022 8:52 pm

display image

Post 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?
BarryG
Addict
Addict
Posts: 4174
Joined: Thu Apr 18, 2019 8:17 am

Re: display image

Post 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/
Sailor
New User
New User
Posts: 5
Joined: Wed Jan 12, 2022 8:52 pm

Re: display image

Post 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?
BarryG
Addict
Addict
Posts: 4174
Joined: Thu Apr 18, 2019 8:17 am

Re: display image

Post 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...
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: display image

Post 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
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
Sailor
New User
New User
Posts: 5
Joined: Wed Jan 12, 2022 8:52 pm

Re: display image

Post 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
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: display image

Post 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.
Sailor
New User
New User
Posts: 5
Joined: Wed Jan 12, 2022 8:52 pm

Re: display image

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: display image

Post 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
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
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: display image

Post 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:
Sailor
New User
New User
Posts: 5
Joined: Wed Jan 12, 2022 8:52 pm

Re: display image

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: display image

Post 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.
BERESHEIT
User avatar
blueb
Addict
Addict
Posts: 1116
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: display image

Post 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.
- 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
Attronach
User
User
Posts: 12
Joined: Tue Sep 19, 2023 9:41 pm

Re: display image

Post 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?
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: display image

Post 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.
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
Post Reply