Bil*_*lly 15 .net c# byte integer casting
我必须使用WinForms在VS2008 .net 3.5中使用以下代码:
byte percent = 70;
byte zero = 0;
Bitmap copy = (Bitmap)image1.Clone();
...
Color oColor = copy.GetPixel(x, y);
byte oR = (byte)(oColor.R - percent < zero ? zero : oColor.R - percent);
Run Code Online (Sandbox Code Playgroud)
当我离开(byte)最后一行代码的" "时,我收到编译器错误,说它"无法隐式转换类型int"到' byte'.如果一切都是类型byte并且byte是整数类型...那么我为什么需要演员?
Cha*_*tin 15
因为减法强制转换为整数.我记得,byte是C#中的无符号类型,因此减法可以将您带出字节域.
sch*_*der 11
那是因为字节减法的结果不适合一个字节:
byte - byte = (0..255) - (0..255) = -255..255
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9676 次 |
| 最近记录: |