Question about the dimensions of an image.

Just starting out? Need help? Post your questions and find answers here.
Armoured
Enthusiast
Enthusiast
Posts: 365
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

Question about the dimensions of an image.

Post 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.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 762
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Question about the dimensions of an image.

Post by spikey »

Do you have the display scaling factor set to 125% by any chance?
Armoured
Enthusiast
Enthusiast
Posts: 365
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

Re: Question about the dimensions of an image.

Post by Armoured »

Hi,
No, it's set to 100%.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 304
Joined: Tue Sep 05, 2017 10:07 am

Re: Question about the dimensions of an image.

Post 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)
Last edited by matalog on Tue Jul 09, 2024 7:39 pm, edited 1 time in total.
Comfort
User
User
Posts: 32
Joined: Thu Jul 05, 2018 11:52 pm

Re: Question about the dimensions of an image.

Post by Comfort »

Try changing the size of the Image... the ImageGadget Width and Height will change with it.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 304
Joined: Tue Sep 05, 2017 10:07 am

Re: Question about the dimensions of an image.

Post 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.
Comfort
User
User
Posts: 32
Joined: Thu Jul 05, 2018 11:52 pm

Re: Question about the dimensions of an image.

Post 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.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 304
Joined: Tue Sep 05, 2017 10:07 am

Re: Question about the dimensions of an image.

Post 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.
Comfort
User
User
Posts: 32
Joined: Thu Jul 05, 2018 11:52 pm

Re: Question about the dimensions of an image.

Post by Comfort »

God... enough of this!
User avatar
matalog
Enthusiast
Enthusiast
Posts: 304
Joined: Tue Sep 05, 2017 10:07 am

Re: Question about the dimensions of an image.

Post 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.
Armoured
Enthusiast
Enthusiast
Posts: 365
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

Re: Question about the dimensions of an image.

Post 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?
Armoured
Enthusiast
Enthusiast
Posts: 365
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

Re: Question about the dimensions of an image.

Post 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!
User avatar
matalog
Enthusiast
Enthusiast
Posts: 304
Joined: Tue Sep 05, 2017 10:07 am

Re: Question about the dimensions of an image.

Post 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?
Post Reply