Page 1 of 1

Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 5:52 pm
by Armoured
Why do I need to use an image that is 600 pixels wide to cover the width of a video window that is 480 pixels wide?

Code: Select all

#Image_0 = 1

CreateImage(#Image_0,600,270)
OpenWindow(0, 0, 0, 480, 329, "", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
CreateMenu(0,WindowID(0))
MenuTitle("Test")
SetWindowColor(0, RGB(0,255,0))

ImageGadget(#Image_0, 0, 0, 480, 209, ImageID(#Image_0))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Could you help me understand why? Thanks.

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 6:00 pm
by spikey
Do you have the display scaling factor set to 125% by any chance?

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 6:20 pm
by Armoured
Hi,
No, it's set to 100%.

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 6:32 pm
by matalog
I ran your program:

Code: Select all

#Image_0 = 1

CreateImage(#Image_0,600,270)
OpenWindow(0, 0, 0, 480, 329, "", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
CreateMenu(0,WindowID(0))
MenuTitle("Test")
SetWindowColor(0, RGB(0,255,0))

ImageGadget(#Image_0, 0, 0, 480, 209, ImageID(#Image_0))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Opened an instance of photoshop and created a document of 480x200 pixels, and this program of yours (with the createimage() at the top fixed to 480) just covers the width image in photoshop.

Maybe you think you are displaying a 600 px image, in which case, you'd need to make your window 600 wide to show it all:

Code: Select all

OpenWindow(0, 0, 0, 600, 329, "", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 6:37 pm
by Comfort
Try changing the size of the Image... the ImageGadget Width and Height will change with it.

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 7:04 pm
by matalog
Comfort wrote: Tue Jul 09, 2024 6:37 pm Try changing the size of the Image... the ImageGadget Width and Height will change with it.
The imagegadget width and height will not change it, not when there is an image specifically added in the same imagegadget.

The problem is the window the user has opened is only 480 wide.

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 7:19 pm
by Comfort
The problem is the window the user has opened is only 480 wide.
Then he needs to change the Image width to 480.

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 7:39 pm
by matalog
Comfort wrote: Tue Jul 09, 2024 7:19 pm
The problem is the window the user has opened is only 480 wide.
Then he needs to change the Image width to 480.
This is from the help file on Imagegadget()
The gadget adjusts its width and height to fit the displayed image. The specified width and height are only used when no image is displayed.

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 7:45 pm
by Comfort
God... enough of this!

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 8:42 pm
by matalog
Comfort wrote: Tue Jul 09, 2024 7:45 pm God... enough of this!
I'm sure the user has grasped that they had a 600 px image open in a 480 window by now. If they want to open a 600px image, they can increase the window size, and if they want a 480 px image open, then they can decrease the image size.

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 9:14 pm
by Armoured
matalog wrote: Tue Jul 09, 2024 6:32 pm I ran your program:

Code: Select all

#Image_0 = 1

CreateImage(#Image_0,600,270)
OpenWindow(0, 0, 0, 480, 329, "", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
CreateMenu(0,WindowID(0))
MenuTitle("Test")
SetWindowColor(0, RGB(0,255,0))

ImageGadget(#Image_0, 0, 0, 480, 209, ImageID(#Image_0))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Opened an instance of photoshop and created a document of 480x200 pixels, and this program of yours (with the createimage() at the top fixed to 480) just covers the width image in photoshop.

Maybe you think you are displaying a 600 px image, in which case, you'd need to make your window 600 wide to show it all:

Code: Select all

OpenWindow(0, 0, 0, 600, 329, "", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)

Compare this:

Code: Select all

#Image_0 = 1

CreateImage(#Image_0,600,270,24,RGB(255,0,0)) ;Note that the width of the image is 600 pixel

OpenWindow(0, 0, 0, 480, 329, "", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
CreateMenu(0,WindowID(0))
MenuTitle("Test")
SetWindowColor(0, RGB(0,255,0))

ImageGadget(#Image_0, 0, 0, 480, 209, ImageID(#Image_0))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
With this:

Code: Select all

#Image_0 = 1

CreateImage(#Image_0,599,270,24,RGB(255,0,0)) ;Note that the width of the image now is 599 pixel

OpenWindow(0, 0, 0, 480, 329, "", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
CreateMenu(0,WindowID(0))
MenuTitle("Test")
SetWindowColor(0, RGB(0,255,0))

ImageGadget(#Image_0, 0, 0, 480, 209, ImageID(#Image_0))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
In the second example, do you see a tiny one-pixel green line on the right?

Re: Question about the dimensions of an image.

Posted: Tue Jul 09, 2024 11:43 pm
by Armoured
I’ve found a fix for the “problem” related to ImageGadget when the DPI aware option is enabled in the compiler settings. NetMaestro provided the solution, and you can find it here: https://www.purebasic.fr/english/viewtopic.php?t=82172.

Thanks to all for the help!

Re: Question about the dimensions of an image.

Posted: Wed Jul 10, 2024 4:52 pm
by matalog
In the second example, do you see a tiny one-pixel green line on the right?
I don't see any green on the right, only at the bottom.

I only see green on the right when I change the image size small enough that there is one pixel of space left so that the image does not fill the width of the window - which is 479 pixels wide, then 1 pixel is showing on the right, because you have the window size set to 480 pixels wide.

Like this, I see one pixel width of green on the right:

Code: Select all

#Image_0 = 1

CreateImage(#Image_0,479,270,24,RGB(255,0,0)) ;Note that the width of the image now is 599 pixel

OpenWindow(0, 0, 0, 480, 329, "", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
CreateMenu(0,WindowID(0))
MenuTitle("Test")
SetWindowColor(0, RGB(0,255,0))

ImageGadget(#Image_0, 0, 0, 480, 209, ImageID(#Image_0))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver

Why are you displaying an image bigger than the window?