How to initialize an image?
How to initialize an image?
Hello! I am a total beginner with purebasic (I do have some experience with tcl/tk and some RealBasic/Xojo).
I've been trying to learn by reading (PureBasic - A Beginners Guide.pdf and the PureBasic reference manual). I'm trying to use ButtonImageGadget but I keep getting "the specified #image is not initialized", however I don't see where I'm doing it wrong. From what I have seen/read I ended with this:
LoadImage(0, #PB_Compiler_Home + "smp1.png")
ButtonImageGadget(#PB_Any, 10, 10, 100, 100, ImageID(0))
I thought LoadImage was "initializing" the image. What am I missing?
(I'm using Linux, if that is important. The image file is in the purebasic directory (I thought this was the place indicated by #PB_Compiler_Home, at least a warning mark disappeared from the LoadImage line when I removed the path to the image file), but my test program is in the example directory.)
I've been trying to learn by reading (PureBasic - A Beginners Guide.pdf and the PureBasic reference manual). I'm trying to use ButtonImageGadget but I keep getting "the specified #image is not initialized", however I don't see where I'm doing it wrong. From what I have seen/read I ended with this:
LoadImage(0, #PB_Compiler_Home + "smp1.png")
ButtonImageGadget(#PB_Any, 10, 10, 100, 100, ImageID(0))
I thought LoadImage was "initializing" the image. What am I missing?
(I'm using Linux, if that is important. The image file is in the purebasic directory (I thought this was the place indicated by #PB_Compiler_Home, at least a warning mark disappeared from the LoadImage line when I removed the path to the image file), but my test program is in the example directory.)
Re: How to initialize an image?
I've been on this path myself, recently.
You can also incorporate an image into the executable program in a DataSection, which makes it independent of external files which might be misplaced, at the cost of a bigger executable, of course. There is a post elsewhere on the forum which relates to using such an entity....
https://www.purebasic.fr/english/viewto ... 11#p410611
and that post contains a link to another topic which gives one way of making the DataSection.
One DataSection can contain many items, each labelled (see the manual).
Bit of a slog, but the result (in Linux, like you) is lightning fast. Useful if you have many images to move around your window during the course of the program.
You can also incorporate an image into the executable program in a DataSection, which makes it independent of external files which might be misplaced, at the cost of a bigger executable, of course. There is a post elsewhere on the forum which relates to using such an entity....
https://www.purebasic.fr/english/viewto ... 11#p410611
and that post contains a link to another topic which gives one way of making the DataSection.
One DataSection can contain many items, each labelled (see the manual).
Bit of a slog, but the result (in Linux, like you) is lightning fast. Useful if you have many images to move around your window during the course of the program.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
Re: How to initialize an image?
Copy the picture folder into your home directory.
This works not on Linux with Compiler Home.
This works not on Linux with Compiler Home.
地球上の平和
Re: How to initialize an image?
Verify that LoadImage() is succeeding
If not working (zero), check that the file path is correct
Like Saki said, make sure you put this before the load
Code: Select all
Debug LoadImage(0, #PB_Compiler_Home + "smp1.png")
Code: Select all
Debug #PB_Compiler_Home + "smp1.png"
Debug FileSize(#PB_Compiler_Home + "smp1.png")
Code: Select all
UsePNGImageDecoder()
Re: How to initialize an image?
Thank you for your replies. I'll try them as soon as I have purebasic working again (for some reason installing it dragged nvidia stuff with it as screwed my system...)
Re: How to initialize an image?
I think that near all is said... You can also add a filesize() test. But I am sure, once this load have been succeed, you won't meet this problem again.
1) To debug, first aspect : name and save your new basic file, even if you did not type anything !
--> [File] --> [Save as] --> type i.e. "mySourceFile.pb"
2) Name your image file.
3) Check if the file is detected by your program.
4) Don't forget the decoder library, as mentionned by Saki.
5) Test your load.
6) Do not forget if the other function use directly the image identifyier (here 10), or the image handle, through ImageID(10).
Normally, this should be better. Try first to copy your image file near your source file (in the same directory).
Have a luck!
1) To debug, first aspect : name and save your new basic file, even if you did not type anything !
--> [File] --> [Save as] --> type i.e. "mySourceFile.pb"
2) Name your image file.
Code: Select all
Define.S ImageName = GetCurrentDirectory() + "myImage.PNG"
Code: Select all
If FileSize(ImageName) >= 0
Debug "Image file detected"
Else
Debug "Image file not detected"
EndIf
Code: Select all
UsePNDImageDecoder()
Code: Select all
If LoadImage(10, ImageName)
Debug "Image detected"
Else
Debug "Image not detected"
EndIf
Normally, this should be better. Try first to copy your image file near your source file (in the same directory).
Have a luck!
Re: How to initialize an image?
Sometimes it is not easy to enter the correct path to a file.
You can simply have the path displayed like this,
then copy that and you're done.
You can simply have the path displayed like this,
then copy that and you're done.
Code: Select all
path$=OpenFileRequester("", "", "", 0)
Debug path$
SetClipboardText(path$) ; This put the path in your clipboard
地球上の平和
-
- New User
- Posts: 1
- Joined: Mon May 24, 2021 8:22 am
Re: How to initialize an image?
Did you try using UsePNGImageDecoder() as suggested? Have you made it work? By the way I've also started with PureBasic - A Beginners Guide; still haven't gone so far with my learning yet...Thank you for your replies. I'll try them as soon as I have purebasic working again (for some reason installing it dragged nvidia stuff with it as screwed my system...)
Re: How to initialize an image?
Sorry, not yet. Soon examination time here so I'm quite busy.
installing dependancies for PureBasic (seems nvidia stuff) screwed my system and I had to reinstall from backup.
As soon as I have time I'll install a system where I can run PureBasic and try all these suggestions.
installing dependancies for PureBasic (seems nvidia stuff) screwed my system and I had to reinstall from backup.
As soon as I have time I'll install a system where I can run PureBasic and try all these suggestions.