ListIconGadget with JPG images

Just starting out? Need help? Post your questions and find answers here.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

ListIconGadget with JPG images

Post by PB »

I'm trying to create a ListIconGadget with 16x16 pixel images for their icons
as previews. The following code doesn't work (you'll need to supply 5 jpg
images called c:\1.jpg, c:\2.jpg, c:\3.jpg, c:\4.jpg, c:\5.jpg). Any ideas?

Note: If I remove the ResizeImage line, it works, but then I only see the
topleft 16 pixels of each image for the icons, which is obviously useless.

Also, it's likely that I'll have a LOT of such icons... is there a limit to the
number of LoadImages I can do in PureBasic? Say, 2000 or so? :shock:
Each image will only be 16x16 pixels in size though, if that helps...

Code: Select all

UseJPEGImageDecoder()

If OpenWindow(0,300,200,300,300,#PB_Window_SystemMenu,"test")
  CreateGadgetList(WindowID())
  ListIconGadget(0,10,10,250,300,"test",200)
  For r=1 To 5
    p+1 : a=LoadImage(p,"c:\"+Str(r)+".jpg")
    ResizeImage(p,16,16)
    AddGadgetItem(0,-1,"Item "+Str(r),a)
  Next
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Splondike
New User
New User
Posts: 6
Joined: Mon Aug 01, 2005 1:47 pm

Post by Splondike »

2000 different icons?! Whew.. Mightent it be better to maybe not load them all at once, ie. load the ones which can currently be seen, as well as a few on either side as a 'buffer':

*Buffered image 1*
*Buffered image 2*
---Viewable---
*Visible Icon 1*
*Visble Icon 2*
----------------
*Buffered image 3*
*Buffered image 4*

I've seen this technique done in the past (i'm sure you have too). They often use a placeholder image which they subsequently replace as the user scrolls to that location. I know this didn't answer your question, but I hope it might help anyways :wink:. Good luck!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> load the ones which can currently be seen, as well as a few on either side
> as a 'buffer'

Yeah, I know that would make more sense, but it was just for a concept app,
so I don't think I'll end up bothering. Trying to show a 640x480 jpeg as a
16x16 icon isn't going to be as useful as I thought. But I'd still be interested
to know why the above snippet of only 5 images doesn't work, if anyone has
an answer. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Re: ListIconGadget with JPG images

Post by Dare2 »

Hi PB, I can't check this right now and just guessing, but ResizeImage changes the handle doesn't it? Would you need to UseImage or something to get the new handle? Otherwise perhaps it is looking at the old unresized instance?

Edit: I guess what I am trying to say is that I think Resize actually makes a new image.
@}--`--,-- A rose by any other name ..
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: ListIconGadget with JPG images

Post by PB »

> ResizeImage changes the handle doesn't it? Would you need to UseImage
> or something to get the new handle?

Yep, that was it... I amended the line in the snippet to this...

Code: Select all

AddGadgetItem(0,-1,"Item "+Str(r),UseImage(p))
...and now it works as expected. Thanks!

@Fred: This is a confusing way to do it... is there perhaps a way to keep the
same image number after a resize in a future release of PureBasic? :?:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

PB,

The image number does not change, but the image handle does.

Code: Select all

Procedure Create_Image(ImageNumber.l, Width.l, Height.l, Color.l, Text.s, FontID.l)
  ImageID = CreateImage(ImageNumber, Width, Height)
  StartDrawing(ImageOutput())
    Box(0, 0, Width, Height, Color)
    DrawingMode(1)
    DrawingFont(FontID)
    BackColor(0, 0, 0)
    FrontColor(255, 255, 255)
    Locate(10, 10)
    DrawText(Text)
  StopDrawing()
EndProcedure

UseJPEGImageDecoder()

FontID = LoadFont(0, "Verdana", 72, #PB_Font_HighQuality)
If OpenWindow(0,300,200,300,300,#PB_Window_SystemMenu,"test")
  CreateGadgetList(WindowID())
  ListIconGadget(0,10,10,250,300,"test",200)
  For r=1 To 5
    p+1 : a = Create_Image(p, 240, 240, RGB(0, 0, 16 * p + 128), Str(p), FontID) ; LoadImage(p,"c:\"+Str(r)+".jpg")
    a = ResizeImage(p,16,16)
    AddGadgetItem(0,-1,"Item "+Str(r),a)
  Next
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
That's it, just use something like :

ImageID = CreateImage() or LoadImage()

and then

ImageID = ResizeImage()

Rgrds
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

fweil wrote:The image number does not change, but the image handle does.
Interesting.

So we have 2 images (original and resized), 1 id number and 2 handles?

How do we free up the original to release the memory?

Thanks!
@}--`--,-- A rose by any other name ..
Post Reply