Page 1 of 1

ImageGadget dimensions

Posted: Wed Sep 27, 2023 11:47 am
by BarryG
I've always found it weird that ImageGadgets resize themselves to the image dimensions that they hold. How about an optional flag for them to stay what the specified gadget width/height actually is (and put the image in the center of it), instead of resizing to what the image width/height is? Like this:

Code: Select all

LoadImage(0,#PB_Compiler_Home+"Examples\Sources\Data\Geebee2.bmp") ; 128 x 128 pixels.
OpenWindow(0,0,0,640,320,"Image Scale",#PB_Window_SystemMenu)
ImageGadget(1,10,10,0,0,ImageID(0)) ; Shown at 128 x 128 (the actual image size, hence why W/H are both set to 0).
ImageGadget(2,200,10,256,256,ImageID(0)) ; Want this ImageGadget to be 256 x 256 without resizing or copying the image.
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Currently I have to use my own procedure to do the job, which isn't ideal and involves copying the source images (LOTS of them).

Re: ImageGadget dimensions

Posted: Wed Sep 27, 2023 12:25 pm
by pjay
I'd use a CanvasGadget for this:

Code: Select all

LoadImage(0,#PB_Compiler_Home+"Examples\Sources\Data\Geebee2.bmp") ; 128 x 128 pixels.
OpenWindow(0,0,0,780,320,"Image Scale",#PB_Window_SystemMenu)
ImageGadget(1,10,10,0,0,ImageID(0)) ; Shown at 128 x 128 (the actual image size, hence why W/H are both set to 0).
ImageGadget(2,200,10,256,256,ImageID(0)) ; Want this ImageGadget to be 256 x 256 without resizing or copying the image.

CanvasGadget(3,400,10,256,256)
Procedure SetCanvasGadgetImage(Gad,Img)
  StartDrawing(CanvasOutput(Gad))
  Box(0,0,OutputWidth(),OutputHeight(),#White) ; (or could obtain window background colour)
  DrawImage(ImageID(Img),(OutputWidth()/2)-(ImageWidth(Img)/2),(OutputHeight()/2) - (ImageHeight(Img)/2))
  StopDrawing()
EndProcedure

SetCanvasGadgetImage(3,0)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: ImageGadget dimensions

Posted: Wed Sep 27, 2023 1:00 pm
by BarryG
Yeah, but that's extra gadgets, code, and memory to do it. I'd love something as simple as this:

Code: Select all

ImageGadget(2,200,10,256,256,ImageID(0),#PB_Image_NoResize) ; So a 128x128 image is centered in it.
My app has over 300 individual images as ImageGadgets, so I don't want to also code an extra 300 CanvasGadgets to do the job.

Re: ImageGadget dimensions

Posted: Sun Nov 03, 2024 2:15 am
by BarryG
Just saw this new post -> viewtopic.php?t=85655

Which is somewhat related to my request here. Can my request be done, please? :)