(Solved) math for resising images for screen display
Posted: Wed Dec 16, 2015 5:06 am
I want to take an image from a database (i can do that), resize it on screen to account for the window frame widths and titlebar height, resize it so it looks fairly 'natural' (Close to the original image) and centre on screen.
I am having a little trouble with the math though. The example below has vague references to gadgets and windows and is only attempting to illustrate my illogic and not reproduce the entire 11,000 line program.
Can anyone see where I am going wrong with my math? Yes, I know I don't know what I am doing when it comes to math calculations so tell me something I don't know:):)
ExamineDesktops()
..Get the desktop work area
DesktopWidth.i = DesktopWidth(0)
DesktopHeight.i = DesktopHeight(0)
..Get the menu and frame widths of the opened window
WinFrameWidth.i = (WindowWidth(#MyWindow, #PB_Window_FrameCoordinate) - WindowWidth(#MyWindow, #PB_Window_InnerCoordinate)) / 2
TitleBarHeight.i = GetWindowTitleBarDetails(#MyWindow)
..The original height and width of a picture loaded from a database blob
PictureHorizontal.i = 2022
PictureVertical.i = 800
..Do desktop related height and width calculations before displaying
HorizontalWidth.i = PictureHorizontal.i - (WinFrameWidth.i * 2)
VerticalHeight.i = PictureVertical.i - TitleBarHeight.i - (WinFrameWidth.i * 2)
..Some debug stuff for me
Debug "Current window frame width: " + Str(WinFrameWidth.i)
Debug "Current window titlebar height: " + Str(TitleBarHeight.i)
Debug "Original picture width: " + Picture\Horizontal
Debug "Original picture height: " + Picture\Vertical
Debug "Picture width minus frame: " + Str(HorizontalWidth.i)
Debug "Picture height minus frame: " + Str(VerticalHeight.i)
..Do desktop related height and width calculations before displaying
If HorizontalWidth.i > DesktopWidth ; If the horizontal width is greater than the desktop
NewWidth.i = DesktopWidth ; Resize it to the desktop width minus the menu bar and frame
ElseIf HorizontalWidth.i < DesktopWidth ; If the horizontal width is less than the desktop
NewWidth.i = PictureHorizontal) ; Resize it to the original picture width minus the menu bar and frame
EndIf
..
If VerticalHeight.i > DesktopHeight ; If the vertical height is greater than the desktop
NewHeight.i = DesktopHeight ; Resize it to the desktop height
ElseIf VerticalHeight.i < DesktopHeight ; If the vertical height is less than the desktop
NewHeight.i = PictureVertical ; Resize it To the original picture minus the menu bar And frame
EndIf
..Now set the resized image to the image gadget
If PictureHandle.i
ResizeWindow(#MyWindow, #PB_Ignore, #PB_Ignore, NewWidth.i, Newheight.i)
ResizeGadget(#MyGadget, #PB_Ignore, #PB_Ignore, NewWidth.i, Newheight.i)
ResizeImage(PictureHandle.i, NewWidth.i, Newheight.i, #PB_Image_Smooth)
SetGadgetState(#MyGadget, ImageID(PictureHandle.i))
EndIf
I am having a little trouble with the math though. The example below has vague references to gadgets and windows and is only attempting to illustrate my illogic and not reproduce the entire 11,000 line program.
Can anyone see where I am going wrong with my math? Yes, I know I don't know what I am doing when it comes to math calculations so tell me something I don't know:):)
ExamineDesktops()
..Get the desktop work area
DesktopWidth.i = DesktopWidth(0)
DesktopHeight.i = DesktopHeight(0)
..Get the menu and frame widths of the opened window
WinFrameWidth.i = (WindowWidth(#MyWindow, #PB_Window_FrameCoordinate) - WindowWidth(#MyWindow, #PB_Window_InnerCoordinate)) / 2
TitleBarHeight.i = GetWindowTitleBarDetails(#MyWindow)
..The original height and width of a picture loaded from a database blob
PictureHorizontal.i = 2022
PictureVertical.i = 800
..Do desktop related height and width calculations before displaying
HorizontalWidth.i = PictureHorizontal.i - (WinFrameWidth.i * 2)
VerticalHeight.i = PictureVertical.i - TitleBarHeight.i - (WinFrameWidth.i * 2)
..Some debug stuff for me
Debug "Current window frame width: " + Str(WinFrameWidth.i)
Debug "Current window titlebar height: " + Str(TitleBarHeight.i)
Debug "Original picture width: " + Picture\Horizontal
Debug "Original picture height: " + Picture\Vertical
Debug "Picture width minus frame: " + Str(HorizontalWidth.i)
Debug "Picture height minus frame: " + Str(VerticalHeight.i)
..Do desktop related height and width calculations before displaying
If HorizontalWidth.i > DesktopWidth ; If the horizontal width is greater than the desktop
NewWidth.i = DesktopWidth ; Resize it to the desktop width minus the menu bar and frame
ElseIf HorizontalWidth.i < DesktopWidth ; If the horizontal width is less than the desktop
NewWidth.i = PictureHorizontal) ; Resize it to the original picture width minus the menu bar and frame
EndIf
..
If VerticalHeight.i > DesktopHeight ; If the vertical height is greater than the desktop
NewHeight.i = DesktopHeight ; Resize it to the desktop height
ElseIf VerticalHeight.i < DesktopHeight ; If the vertical height is less than the desktop
NewHeight.i = PictureVertical ; Resize it To the original picture minus the menu bar And frame
EndIf
..Now set the resized image to the image gadget
If PictureHandle.i
ResizeWindow(#MyWindow, #PB_Ignore, #PB_Ignore, NewWidth.i, Newheight.i)
ResizeGadget(#MyGadget, #PB_Ignore, #PB_Ignore, NewWidth.i, Newheight.i)
ResizeImage(PictureHandle.i, NewWidth.i, Newheight.i, #PB_Image_Smooth)
SetGadgetState(#MyGadget, ImageID(PictureHandle.i))
EndIf