another noob question - image sizes

Just starting out? Need help? Post your questions and find answers here.
namrepus
New User
New User
Posts: 3
Joined: Tue May 23, 2023 3:09 am

another noob question - image sizes

Post by namrepus »

Why in the included Hello World example are the window created with openwindow and the image created with createimage different sizes when the same width and height have been specified?

If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateImage(0, 200, 200) And StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Transparent)
Box(0, 0, 200, 200, RGB(255, 255, 255))
For i = 1 To 30
DrawText(Random(200), Random(200), "Hello World!", RGB(Random(255), Random(255), Random(255)))
Next i
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(0))
EndIf

Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: another noob question - image sizes

Post by jassing »

namrepus wrote: Tue May 23, 2023 3:14 am Why in the included Hello World example are the window created with openwindow and the image created with createimage different sizes when the same width and height have been specified?
Why do you think the image is a different size?
If you resize the window, you can see the image the right size...
If you're referring to the window being slightly bigger due to borders, well; that's the borders...
-j

You should use code tags

Code: Select all

  If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
    If CreateImage(0, 200, 200) And StartDrawing(ImageOutput(0))
      DrawingMode(#PB_2DDrawing_Transparent)
      Box(0, 0, 200, 200, RGB(255, 255, 255))
      For i = 1 To 30
        DrawText(Random(200), Random(200), "Hello World!", RGB(Random(255), Random(255), Random(255)))
      Next i
      StopDrawing() 
      ImageGadget(0, 0, 0, 200, 200, ImageID(0))
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
BarryG
Addict
Addict
Posts: 4123
Joined: Thu Apr 18, 2019 8:17 am

Re: another noob question - image sizes

Post by BarryG »

namrepus wrote: Tue May 23, 2023 3:14 amWhy in the included Hello World example are the window created with openwindow and the image created with createimage different sizes when the same width and height have been specified?
Because the manual says this for window sizes with the OpenWindow() command:
Manual wrote:InnerWidth, InnerHeight: The required client area, in pixels (without borders and window decorations).
So your inner window size and image size are actually both 200 pixels, as shown by modifying your example with a red image border:

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  If CreateImage(0, 200, 200) And StartDrawing(ImageOutput(0))
    DrawingMode(#PB_2DDrawing_Transparent)
    Box(0, 0, 200, 200, RGB(255, 255, 255))
    For i = 1 To 30
      DrawText(Random(200), Random(200), "Hello World!", RGB(Random(255), Random(255), Random(255)))
    Next i
    DrawingMode(#PB_2DDrawing_Outlined)
    Box(0, 0, 200, 200, #Red)
    StopDrawing() 
    ImageGadget(0, 0, 0, 200, 200, ImageID(0))
  EndIf
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: another noob question - image sizes

Post by Crusiatus Black »

Do you have resolution scaling set to i.e. 125% or 150%? You can try with the scaled sizes:

Code: Select all

#SIZEXY = 400

If OpenWindow(0, 0, 0, #SIZEXY, #SIZEXY, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  scaledX = DesktopScaledX(#SIZEXY)
  scaledY = DesktopScaledY(#SIZEXY)
  
  If CreateImage(0, scaledX, scaledY) And StartDrawing(ImageOutput(0))
    DrawingMode(#PB_2DDrawing_Transparent)
    Box(0, 0, scaledX, scaledY, RGB(255, 255, 255))
    For i = 1 To 30
      DrawText(Random(scaledX), Random(scaledY), "Hello World!", RGB(Random(255), Random(255), Random(255)))
    Next i
    DrawingMode(#PB_2DDrawing_Outlined)
    Box(0, 0, scaledX, scaledY, #Red)
    StopDrawing() 
    ImageGadget(0, 0, 0, scaledX, scaledY, ImageID(0))
  EndIf
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
namrepus
New User
New User
Posts: 3
Joined: Tue May 23, 2023 3:09 am

Re: another noob question - image sizes

Post by namrepus »

ok...
My bad.
Evidently it was something specific to my laptop at home as the computer at works shows everything as expected.
thanks for the help everyone.
I have another fun mystery :)
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: another noob question - image sizes

Post by Crusiatus Black »

namrepus wrote: Wed May 24, 2023 12:48 pm ok...
My bad.
Evidently it was something specific to my laptop at home as the computer at works shows everything as expected.
thanks for the help everyone.
I have another fun mystery :)
Indeed, it might be the resolution scaling in that case
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
namrepus
New User
New User
Posts: 3
Joined: Tue May 23, 2023 3:09 am

Re: another noob question - image sizes

Post by namrepus »

was indeed screen scaling, thanks... important safety tip...
Post Reply