我有一個寬度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