Page 1 of 1

ListIconGadget with JPG images

Posted: Sat Aug 13, 2005 3:49 am
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

Posted: Sat Aug 13, 2005 5:13 am
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!

Posted: Sat Aug 13, 2005 6:06 am
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. :)

Re: ListIconGadget with JPG images

Posted: Sat Aug 13, 2005 7:35 am
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.

Re: ListIconGadget with JPG images

Posted: Sat Aug 13, 2005 8:45 am
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? :?:

Posted: Sat Aug 13, 2005 10:09 am
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

Posted: Sat Aug 13, 2005 2:05 pm
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!