Get image gadget's handle?

Just starting out? Need help? Post your questions and find answers here.
ekix
User
User
Posts: 34
Joined: Thu Apr 21, 2005 7:43 pm
Location: Finland
Contact:

Get image gadget's handle?

Post by ekix »

Hello guys

I have some images preloaded as below to compile with the program (so, I want to get them included inside of the final compiled exe-file).

Code: Select all

DataSection
Image0:
  IncludeBinary "C:\Colors for PB\Image1.jpg"
Image1:
  IncludeBinary "C:\Colors for PB\Image2.jpg"
Image2:
  IncludeBinary "C:\Colors for PB\Image3.jpg"
Image3:
  IncludeBinary "C:\Colors for PB\Image4.jpg"
EndDataSection
etc... all done using Visual Designer...

I would like to get the same value to a variable as Debug gives me.

Code: Select all

For Picture = 0 To 4
    Debug (Picture)
    Result = ImageID(Picture)
    Debug Result
Next
Debug gives me right values from 0 to 4 but ImageID(Picture) gives me weird numbers as below:

0
-754642828
1
-234549321
2
151325117
3
2047151689
4
805638195

I just can't figure out how to get these debug values (0-4) to a variable as Result for example
Any idea how to do it, maybe I just missed something or am I just stupid once again?

Regards/
Ekix
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Those wierd numbers are the ImageId / image handle. If you are looking to get the image number from the ImageId, try this...

Code: Select all

For Picture = 0 To 4
  Debug (Picture) 
  result = ImageID(Picture) 
  Debug PeekL(@result - 4)
Next
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
ekix
User
User
Posts: 34
Joined: Thu Apr 21, 2005 7:43 pm
Location: Finland
Contact:

Thanks Sparkie

Post by ekix »

Looks like I can now assign numeric and string variables to pictures as below:

Code: Select all

    For Picture = 0 To 2
       Debug ImageID(Picture) 
       Debug PeekL(@result - 4)
       Picture = PeekL(@result - 4)
       Debug Picture
       Picture$ = Str(Picture)
       MessageRequester("Picture information", "Picture = "+Picture$ , #PB_MessageRequester_Ok)
    Next
 
386208632
0
0
235213978
1
1
-1660611398
2
2
Is this is the only way to do the it?
Very difficult to find from PB's help (impossible I would say), how did you ever solve/know this kind of a trick and does it work with all processors and in Vista also the same way, for me peek'ing and poke'ing feels like read/write from memory?

Thanks a lot Sparkie :D
ekix
User
User
Posts: 34
Joined: Thu Apr 21, 2005 7:43 pm
Location: Finland
Contact:

Filename?

Post by ekix »

I have some images preloaded as above and I was just wondering how to get the preloaded images filename (with or without the filepath)?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

ekix wrote:Is this is the only way to do the it?
Yes, AFAIK.
ekix wrote:Very difficult to find from PB's help (impossible I would say), how did you ever solve/know this kind of a trick...
I took a wild guess. 8)
ekix wrote:...and does it work with all processors and in Vista also the same way,...
It should, but since it's an undocumented hack, I wouldn't bet the ranch on it. :wink:
...for me peek'ing and poke'ing feels like read/write from memory?
Yes.
ekix wrote:Thanks a lot Sparkie
You are welcome. :)
ekix wrote:I have some images preloaded as above and I was just wondering how to get the preloaded images filename (with or without the filepath)?
I don't think that will be possible. You'll need to store the filenames yourself for later retrieval.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
freak
PureBasic Team
PureBasic Team
Posts: 5944
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Sparkie wrote:Those wierd numbers are the ImageId / image handle. If you are looking to get the image number from the ImageId, try this...

Code: Select all

For Picture = 0 To 4
  Debug (Picture) 
  result = ImageID(Picture) 
  Debug PeekL(@result - 4)
Next
What is this code supposed to do ?
"PeekL(@result - 4)" reads the value before the "result" variable, this is the "Picture" variable. It has nothing to do with ImageID()

See these two: You just peek at the variable just before the current one. Whats the use ?

Code: Select all

For Picture = 0 To 4
  Debug (Picture)
  result = 0
  Debug PeekL(@result - 4)  ; this just reads whatever is in Picture
Next 

Code: Select all

For Picture = 0 To 4
  Debug (Picture)
  Picture2 = 5
  result = 0
  Debug PeekL(@result - 4)  ; now you are peeking at Picture2
Next 
You cannot get the PB number from an ImageID. This value is stored nowhere on the image object.
quidquid Latine dictum sit altum videtur
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

No wonder it seemed too easy...senior moment here. Thanks freak :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
ekix
User
User
Posts: 34
Joined: Thu Apr 21, 2005 7:43 pm
Location: Finland
Contact:

Confused again.....

Post by ekix »

Sorry guys, but now you made me a bit confused. What I would like to do, is preload/compile series of images and then hide/show them and show also the name of the image (in this example in a msgbox). Because I cannot read the filename with Peek command I just use Picture$ for this.
Anyway at the moment I'm using code as below:

Code: Select all

    For Picture = 1 To 17
      If Picture=1
        HideGadget(1, 0)
            Picture = PeekL(@result - 4)
    Picture$ = " Red "
    
    MessageRequester("Picture information", "Tekstiväri = "+Picture$ , #PB_MessageRequester_Ok)
      ElseIf Picture=2
        HideGadget(2, 0)
            Picture = PeekL(@result - 4)
    Picture$  = " Green "
etc...

So I cannot understand how should I actually change my code to work in proper way?
Sorry for I'm a bit confused (as most of the time normally...)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

ekix wrote:Sorry guys, but now you made me a bit confused.
You're not alone, believe me. :)

Fist of all the trick I showed you was no trick. It was my not thinking clearly that made it appear to be a trick. I tricked myself :shock: :oops:

Code: Select all

Debug PeekL(@result - 4)
As freak pointed out, this is just reading the value stored in the var Picture and is NOT reading the actual image number you assigned to it. My bad and I'm sorry to have added to your confusion.

Try storing the image numbers/id's/filenames in a structred array or somesuch so as to be able to retrieve the data as needed.

Let me shake the cobwebs out of my head and I'll see what I can come up for you.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

This may not be the most efficient method but it should give you some idea of what I was talking about. You decide what information you need and then store it in a manner that works for you. ;)

Code: Select all

UseJPEGImageDecoder()

Structure IMAGESTUFF
  iNumber.i
  iID.i
  iPath.s
  iColor.s
EndStructure

Dim info.IMAGESTUFF(2)

info(0)\iNumber = 0
info(0)\iPath = "C:\Colors for PB\Image0.jpg"
info(0)\iColor = "Red"

info(1)\iNumber = 1
info(1)\iPath = "C:\Colors for PB\Image1.jpg"
info(1)\iColor = "Green"

info(2)\iNumber = 2
info(2)\iPath = "C:\Colors for PB\Image2.jpg"
info(2)\iColor = "Blue"

For Picture = 0 To 2 
  Select Picture
    Case 0
      info(0)\iID = CatchImage(Picture, ?Image0)
    Case 1
      info(1)\iID = CatchImage(Picture, ?Image1)
    Case 2
      info(2)\iID = CatchImage(Picture, ?Image2)
  EndSelect
Next

For Picture = 0 To 2 
  MessageRequester("Picture information", "Number: " + Str(Picture) + #CRLF$ + "ID: " + Str(info(Picture)\iID) + #CRLF$ + "Color: " + info(Picture)\iColor + #CRLF$ + "Path: " + info(Picture)\iPath, #PB_MessageRequester_Ok) 
Next
  
DataSection 
Image0: 
IncludeBinary "C:\Colors for PB\Image0.jpg" 
Image1: 
IncludeBinary "C:\Colors for PB\Image1.jpg" 
Image2: 
IncludeBinary "C:\Colors for PB\Image2.jpg" 
EndDataSection
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
ekix
User
User
Posts: 34
Joined: Thu Apr 21, 2005 7:43 pm
Location: Finland
Contact:

Thanks :=)

Post by ekix »

Thanks again Sparkie

Look's like working exactly what I was looking for. I did test it just but embeddind your code into my own small project.

You guys are Professionals, I feel I've got so much to lear still :oops:, but it's fun and and I like PureBasic more and more because I can get help almost immediatly from you guys here in this Forum...
Post Reply