There are 3 ways of resizing an image/video in a dialog that are of interest to me.
1. centered and not resized
2. centered and resized to fit within a dialog
3. centered and resized to fill the dialog
An image/video could be positioned anywhere within the dialog but I'm most interested in having the center of the image/video to be at the center of of the dialog while maintaining the image/video aspect ratio.
In the following equations, w/h is dialog size and wRes/hRes is video frame size (resolution). wNew/hNew is the displayed size of the video window.
Resizing Options:
There are 3 possible constraints on resizing the image/video that are of interest:
1. image/video window size is not resized, just centered over the dialog
wNew = wRes
hNew = hRes
2. image/video is resized to fit within the dialog client area. there may be empty borders. none of the image/video will be outside the dialog client area.
wNew = wRes / Max(wRes / w, hRes / h)
hNew = hRes/ Max(wRes / w, hRes / h)
3. video window is resized to fill the dialog. there will be no empty borders. two opposing sizes of the video window will be outside the dialog client area unless image/video size = dialog client size.
wNew = wRes / Min(wRes / w, hRes / h)
hNew = hRes/ Min(wRes / w, hRes / h)
In all three cases, this equation would apply to the position/size of the displayed image/video:
SetWindowPosition(w/2-0.5*wNew,h/2-0.5*hNew,wNew,hNew)
1. centered and not resized
2. centered and resized to fit within a dialog
3. centered and resized to fill the dialog
An image/video could be positioned anywhere within the dialog but I'm most interested in having the center of the image/video to be at the center of of the dialog while maintaining the image/video aspect ratio.
In the following equations, w/h is dialog size and wRes/hRes is video frame size (resolution). wNew/hNew is the displayed size of the video window.
Resizing Options:
There are 3 possible constraints on resizing the image/video that are of interest:
1. image/video window size is not resized, just centered over the dialog
wNew = wRes
hNew = hRes
2. image/video is resized to fit within the dialog client area. there may be empty borders. none of the image/video will be outside the dialog client area.
wNew = wRes / Max(wRes / w, hRes / h)
hNew = hRes/ Max(wRes / w, hRes / h)
3. video window is resized to fill the dialog. there will be no empty borders. two opposing sizes of the video window will be outside the dialog client area unless image/video size = dialog client size.
wNew = wRes / Min(wRes / w, hRes / h)
hNew = hRes/ Min(wRes / w, hRes / h)
In all three cases, this equation would apply to the position/size of the displayed image/video:
SetWindowPosition(w/2-0.5*wNew,h/2-0.5*hNew,wNew,hNew)
Comment