Page 1 of 1

another noob question - image sizes

Posted: Tue May 23, 2023 3:14 am
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

Re: another noob question - image sizes

Posted: Tue May 23, 2023 4:27 am
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

Re: another noob question - image sizes

Posted: Tue May 23, 2023 6:05 am
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

Re: another noob question - image sizes

Posted: Tue May 23, 2023 7:58 am
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

Re: another noob question - image sizes

Posted: Wed May 24, 2023 12:48 pm
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 :)

Re: another noob question - image sizes

Posted: Wed May 24, 2023 9:46 pm
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

Re: another noob question - image sizes

Posted: Thu May 25, 2023 2:36 am
by namrepus
was indeed screen scaling, thanks... important safety tip...