本人在DotNet中使用了第三方控件其中Uint类型,据.Net帮助中描述,Uint对应.Net中int类型,原本就可直接转换,为什么转换后的值与结果为什么会不同?int -2,147,483,648 到 2,147,483,647 有符号 32 位整数 uint 0 到 4,294,967,295 无符号 32 位整数 哪之间转换是不是有特殊的方式
第一个问题:
通过一个
Color.FromArgb(210,210,210).ToArgb()获取一个RGB值(RGB是灰色)并直接转换成((uint)Color.FromArgb(210,210,210).ToArgb())uint类型,显示的结果是暗红色。我该如何用正确的转换成uint值?
第二个:
byte[] MyData = wfd.FlowImage;//这是个大对象 MyData决对有值,
MyData是个byte[]类型,MyData如何转换Uint类型。
第一个问题:
通过一个
Color.FromArgb(210,210,210).ToArgb()获取一个RGB值(RGB是灰色)并直接转换成((uint)Color.FromArgb(210,210,210).ToArgb())uint类型,显示的结果是暗红色。我该如何用正确的转换成uint值?
第二个:
byte[] MyData = wfd.FlowImage;//这是个大对象 MyData决对有值,
MyData是个byte[]类型,MyData如何转换Uint类型。
Dim myColor As Color = Color.Red
' Translate myColor to an OLE color.
Dim winColor As Integer = ColorTranslator.ToWin32(myColor)
(uint)ColorTranslator.ToWin32(olor.FromArgb(210,210,210))
或
(uint)ColorTranslator.ToOle(olor.FromArgb(210,210,210))
--------------------------------
这个长度是多少,是4个字节吗?(MyData.Lentgh == 4) 成立否?
for (int i = 0; i < MyData.Length / 4; i++)
{
n[i] = BitConverter.ToUInt32(MyData, i*4);
}
_xlRange.Font.Color = System.Drawing.ColorTranslator.ToOle(_excelFont.ForeColor);其它的转换楼主可以试试类似方法下面是我试验的其它过程,当时也苦啊,希望朋友们遇到类似问题时不再这么苦了:)
//读者在这要注意:在这需要一个转换的过程,我试了好长时间。
//经过反向读取单格的颜色,发现返回的是double型
//_xlRange.Font.Color = new byte[]{color.R,color.G,color.B}; //color.ToArgb();
//_xlRange.Font.Color = Convert.ToInt32(color.ToArgb()); //用此种后,蓝红颠倒了,绿色正好不变 if (!_excelFont.ForeColor.IsEmpty)
{
_xlRange.Font.Color = System.Drawing.ColorTranslator.ToOle(_excelFont.ForeColor);
}// if (!_excelFont.Background.IsEmpty)
// {
// _xlRange.Font.Background = System.Drawing.ColorTranslator.ToOle(_excelFont.Background);
// }
字节转成int32就是用BitConverter.ToInt32这个方法的
转换成int,在第三方控件中flow.LoadMemory(int HMem)方法中HMem这个参数是一个大对象的句柄才对是不是?。哪byte[] MyData 这个对象的句柄是多少了?
---------------------------------一个大对象的句柄无法从 byte [] MyData 得到,你看一下是否有:int HMem = wfd.HMem 这个属性。
System.RuntimeTypeHandle handle = Type.GetTypeHandle(MyData);
MessageBox.Show(handle.Value.ToInt32().ToString());或者直接取wfd.FlowImage对象的句柄
System.RuntimeTypeHandle handle = Type.GetTypeHandle(wfd.FlowImage);
MessageBox.Show(handle.Value.ToInt32().ToString());