I’m currently writing a program that requires a preview of a live display, but the preview, of course, is scaled down. However, when I scale the PictureBox down, the size is incorrect. For the scale to be correct the width and height need to be at a 4:3 ratio. Here’s the code:
private void FindOptimalRes(PictureBox picBox)
{
double h = Height / 4;
double ratio = 4 / 3;
picBox.Size = new Size((int)(h * ratio), (int)h);
}
In testing, Height (the height of the form) is 400, so, the width of the new size should be 133. But it always gets resized to 100×100! Why?
4and3are bothints, so it gets turned to1. Make them something floating-point:Note that you’re also making the same mistake with
Height(it doesn’t matter right now, but it will – change it to4.0). And if this is the actual code, why divide by four to multiply by four again?