如何在C#中引用指向锯齿状数组的指针 [英] How to refer pointer to jagged array in C#

查看:95
本文介绍了如何在C#中引用指向锯齿状数组的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我试图用指针参数调用DLL函数,

但是我要引用的params是锯齿状数组,所以我现在必须将数组引用到指针并传递调用DLL函数的指针值。



注意:我正在使用VISUAL STUDIO 2010



我试过的:



DLL函数

hi every one I am trying to call the DLL function with pointer parameters,
but my params which I have to refer are in jagged array , so I now have to refer array to pointer and pass pointer values to call DLL function.

note: I am using VISUAL STUDIO 2010

What I have tried:

the DLL function

[DllImport("BYRTORGB.dll")]
 public unsafe static extern void bayer2rgb24(byte* dst1, byte* src2, Int32 width, Int32 height);





我调用DLL函数的代码。





the code I am calling to the DLL function.

unsafe
 {
   byte[][] dbuff = new byte[k][];
   fixed (byte* source = xBufs[k], dest = dbuff[k])
                                           {
   bayer2rgb24( dest, source, width, height);
   fs.Write(dbuff[k], 0, dbuff[k].Length);

推荐答案

2天前你提出这个问题:如何在C#中转换byte [] ato字节 [ ^ ]

你被告知:

When you asked this question 2 days ago: How to convert byte[] ato byte in C#[^]
You were told:
引用:

你不能直接传递一个二维数组,因为排列数据不一样。

更糟糕的是,你试图apss的不是一个基本的2D数组 - 它是一个锯齿状的数组 - 这意味着这些行的长度不一样,或者甚至出现在某些情况下。

由于名称dst意味着一维数组将被被调用的函数用作输出,因此将ti设置为正确且锯齿状是非常重要的数组绝对不合适,因为它是第一角钱nsion实际上是对单个字节数组的引用数组。

You can't directly pass a two dimensional array, because the "arrangement" of the data is not the same.
Even worse, what you are trying to apss is not a "basic" 2D array - it's a jagged array - which means that the lines are not all the same length, or even present in some cases.
Since the name dst implies that the one dimensional array is going to be used by the called function as an output, it is vitally important to get ti right, and a jagged array is definitely not suitable, as it's first dimension is actually an array of references to individual arrays of bytes.





你不能将锯齿状数组传递给你的函数,假设它可以工作:你需要创建一维字节数组,传递它,并在获得数据后将其后处理到2D锯齿状数组中,并找出破坏数组的位置。



You cannot pass a jagged array to your function assuming that it will work: You need to create a 1D array of bytes, pass that, and probably post-process it into your 2D jagged array once you have the data, and can work out where to "break" the array.


这篇关于如何在C#中引用指向锯齿状数组的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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