Dividing by two integers does not return expected result

前端 未结 6 608
甜味超标
甜味超标 2021-01-25 13:18

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, t

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-25 13:26

    4 and 3 are both ints, so it gets turned to 1. Make them something floating-point:

    double ratio = 4.0 / 3.0;
    

    Note that you're also making the same mistake with Height (it doesn't matter right now, but it will - change it to 4.0). And if this is the actual code, why divide by four to multiply by four again?

    private void FindOptimalRes(PictureBox picBox)
    {
        picBox.Size = new Size(Height / 3, Height / 4);
    }
    

提交回复
热议问题