它有可能获得从一个int []数组一个IntPtr? [英] It is possible to get an IntPtr from an int[] array?

查看:258
本文介绍了它有可能获得从一个int []数组一个IntPtr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候

在C#中:如果我有一个int []数组声明如下

In C#: If I have an int[] array declared like this

int[] array = new array[size];



还有一个办法从这个数组得到的IntPtr?

there is an way to get the IntPtr from this array?

的事情是,我使用的EmguCV框架,有一个构造函数来创建这需要一个IntPtr的像素数据,以便从一个阵列构建一个图像的图像(INT [])

The thing is that I'm using the EmguCV framework, and there is an constructor to create an image which takes an IntPtr to the pixel data, in order to build an image from an array (int[]).

Image<Gray,Int32> result = new Image<Gray,int>(bitmap.Width,bitmap.Height,stride,"**array.toPointer??**");



顺便说一句,如果有人可以告诉我如何计算的步伐,这将是巨大的。

By the way if someone could told me how to calculate the stride, that would be great.

推荐答案

您应该能够做到这一点,而无需使用的GCHandle 不安全的代码。这里有一个例子:

You should be able to do this without unsafe code using GCHandle. Here is a sample:

GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
try
{
    IntPtr pointer = handle.AddrOfPinnedObject();
}
finally
{
    if (handle.IsAllocated)
    {
        handle.Free();
    }
}

这篇关于它有可能获得从一个int []数组一个IntPtr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆