简体   繁体   English

从C#到VB.Net的位映射转换

[英]Bit mapping conversion from C# to VB.Net

I'm trying to convert some C# code to VB.Net. 我正在尝试将一些C#代码转换为VB.Net。 See the following: 请参阅以下内容:

C#: C#:

private const ushort SO_IMAGE_RAW = 1;
private const ushort SO_IMAGE_DIB = 2;
private const ushort SO_IMAGE_DCM = 3;
private const ushort SO_IMAGE_BITDEPTH = 12;
private const ushort SO_IMAGE_FORMAT = SO_IMAGE_RAW;
int format = (SO_IMAGE_BITDEPTH << 16) + (SO_IMAGE_FORMAT & 0x0000FFFF);

From the watcher: format=786433 int // This is correct value. 来自观察者:format = 786433 int //这是正确的值。

VB.Net: VB.Net:

Private Const SO_IMAGE_RAW As UShort = 1
Private Const SO_IMAGE_DIB As UShort = 2
Private Const SO_IMAGE_DCM As UShort = 3
Private Const SO_IMAGE_BITS As UShort = 12
Private Const SO_IMAGE_FORMAT = SO_IMAGE_RAW
Dim format As Integer = (SO_IMAGE_BITS << 16) + (SO_IMAGE_FORMAT And &HFFFF)

From the watcher: format=13 Integer '' This is incorrect value. 来自观察者:format = 13 Integer''这是不正确的值。

Any ideas why? 有什么想法吗?

Thanks. 谢谢。

Change the constants to integers and you get the same result as C#: 将常量更改为整数,您将得到与C#相同的结果:

Private Const SO_IMAGE_RAW As Integer = 1
Private Const SO_IMAGE_DIB As Integer = 2
Private Const SO_IMAGE_DCM As Integer = 3
Private Const SO_IMAGE_BITDEPTH As Integer = 12
Private Const SO_IMAGE_FORMAT As Integer = SO_IMAGE_RAW

I'm not quite sure why this is necessary, but the following post might shed some light: Binary Shift Differences between VB.NET and C# 我不太确定为什么需要这样做,但是下面的文章可能会引起一些启发: VB.NET和C#之间的二进制移位差异

Another option - perhaps easier to stomach, is to keep the constants the same, but just use a cast: 另一个选择-也许更容易接受,是使常数保持不变,但是只需使用强制转换:

Dim format As Integer = (CInt(SO_IMAGE_BITDEPTH) << 16) + (SO_IMAGE_FORMAT And &HFFFF)

I think you forgot to specify the datatype in this line 我认为您忘记在这一行中指定数据类型

Private Const SO_IMAGE_FORMAT = SO_IMAGE_RAW

try changing it to 尝试将其更改为

Private Const SO_IMAGE_FORMAT As UShort = SO_IMAGE_RAW

EDIT: 编辑:

this is also a great tool to convert c# code to vb.net 也是将c#代码转换为vb.net的好工具

Private Const SO_IMAGE_RAW As UShort = 1
Private Const SO_IMAGE_DIB As UShort = 2
Private Const SO_IMAGE_DCM As UShort = 3
Private Const SO_IMAGE_BITDEPTH As UShort = 12
Private Const SO_IMAGE_FORMAT As UShort = SO_IMAGE_RAW
Private format As Integer = (SO_IMAGE_BITDEPTH << 16) + (SO_IMAGE_FORMAT And &Hffff)

Convert C# to VB.NET link1 将C#转换为VB.NET link1

Convert C# to VB.NET link2 将C#转换为VB.NET link2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM