C#用byte[]字节数组获取C中byte*指针
2010-12-27 14:58
691 查看
在C中,byte*对应C#中Sbyte,所以没有直接转换的机制,目前开发过程中发现采用System.Runtime.InteropServices.Marshal还是一个不错的选择,,详情请参考如下代码:
接口调用文件中,用句柄获取C中byte*,
[DllImport("MKL_Camera.dll", EntryPoint = "MKL_CaptureBuffer")
public static extern IntPtr MKL_CaptureBuffer(capture_type captureType,ref int size);
将内存中的buffer保存到byte[]中。
IntPtr buffer = camera.MKL_CaptureBuffer(camera.capture_type.TYPE_CAPTURE_JPG, ref size);
byte[] byte1 = new byte[size];
System.Runtime.InteropServices.Marshal.Copy(buffer, byte1, 0, size);
记得要释放buffer
if (buffer != IntPtr.Zero)
{
camera.MKL_ReleaseBuffer(buffer);
buffer = IntPtr.Zero;
}
接口调用文件中,用句柄获取C中byte*,
[DllImport("MKL_Camera.dll", EntryPoint = "MKL_CaptureBuffer")
public static extern IntPtr MKL_CaptureBuffer(capture_type captureType,ref int size);
将内存中的buffer保存到byte[]中。
IntPtr buffer = camera.MKL_CaptureBuffer(camera.capture_type.TYPE_CAPTURE_JPG, ref size);
byte[] byte1 = new byte[size];
System.Runtime.InteropServices.Marshal.Copy(buffer, byte1, 0, size);
记得要释放buffer
if (buffer != IntPtr.Zero)
{
camera.MKL_ReleaseBuffer(buffer);
buffer = IntPtr.Zero;
}
相关文章推荐
- C# 图片与字节数组(byte[])二进制相互转换,获取大小像素扩展名
- C#获取中文英文混合字符串Byte字节长度
- 获取文件字节数组byte[]
- c#设置或者获取byte(字节、8位二进制整数)某位的的值的代码。
- [VB.Net]获取对象的指针及结构体与字节数组间的相互转化
- C#获取中文英文混合字符串Byte字节长度
- C# 中字符串string和字节数组byte[]的转换
- C#指针与字节数组的操作
- C# 三种字节数组(byte[])拼接的性能对比测试
- c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换
- C# 中字符串string和字节数组byte[]之间的转换
- C# 三种字节数组(byte[])拼接的性能对比测试
- C# 常见的字节数组 byte[] 复制方法
- C#获取中文英文混合字符串Byte字节长度
- c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换
- C# int字节 转换Byte数组 3位
- c#设置或者获取byte(字节、8位二进制整数)某位的的值的代码
- 图片获取字节数组byte[]data, 将字节数组转换为String,之后再由String转换为byte[]data,会发现不同
- C#中字节数组(byte[])和字符串相互转换
- C#中获取数组指针再将其转换成IntPtr类型