这里的问题是我有一个大小为 x x y 的显示窗口,我需要在窗口内显示图像而不进行任何滚动,并保持 4:3 的纵横比。我有以下代码片段:
// Lock the current height, calculate new width of the canvas and scale the viewport.
// get width of the movie canvas
qreal width = canvas_->width();
// Find the height of the video
qreal height = (width/4.0) * 3;
// find original width and height for video to calculate scaling factor
qreal videoWidth = movieData_->GetWidth();
qreal videoHeight = movieData_->GetHeight();
// calculate scaling factor
qreal scaleFactorWidth = width/videoWidth;
qreal scaleFactorHeight = height/videoHeight;
当然,通过使用高度或宽度作为“锚点”,新图像将导致滚动(假设原始图像首先大于窗口)。如何找到适合预定尺寸的宽高比 4:3 的尺寸?
编辑 我需要传入 x 和 y 的比例因子来进行缩放
canvas_->scale(scaleFactorWidth, scaleFactorHeight);