我有一个宽度888px和高度592px,宽高比为3:2的图像。Visual Studio 2015说'演员阵容是多余的'。为什么?
下产生的1一个错误的值,因为整数计算/截断的作为BitmapDecoder.PixelWidth和BitmapDecoder.PixelHeight均为uint
(无符号整数),和下面decoder
是一个BitmapDecoder对象。
double aspectRatio = decoder.PixelWidth/decoder.PixelHeight;
下面给出了1.5的预期正确的值,但Visual Studio中说:“演员是多余的”,但为什么呢?
double aspectRatio = (double)decoder.PixelWidth/(double)decoder.PixelHeight;
你只需要一个(双)铸 - double/int = double。或者int/double = double。 – Dmitriy
如果您用任何数字类型划分双精度型,结果将始终为双精度型。 –
'double aspectRatio = static_cast(decoder.PixelWidth)/ decoder.PixelHeight;'应该足以使编译器使用'PixelHeight'作为double。 –
Pixelchemist