可以从int 数组中获取IntPtr吗?
问候。
在C#中:如果我有一个像这样声明的int []数组
int[] array = new array[size];
有一种方法可以从这个数组中获取IntPtr吗?
问题是我正在使用EmguCV框架,并且有一个构造函数来创建一个图像,它将IntPtr带到像素数据,以便从数组(int [])构建图像。
Image result = new Image(bitmap.Width,bitmap.Height,stride,"**array.toPointer??**");
顺便说一句,如果有人能告诉我如何计算步幅,这将是伟大的。
您应该能够使用GCHandle
没有不安全代码的情况下执行此GCHandle
。 这是一个示例:
GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); try { IntPtr pointer = handle.AddrOfPinnedObject(); } finally { if (handle.IsAllocated) { handle.Free(); } }
使用不安全的代码,如下所示:
上述就是C#学习教程:可以从int 数组中获取IntPtr吗?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
unsafe { fixed (int* pArray = array) { IntPtr intPtr = new IntPtr((void *) pArray); } }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/983437.html