在unity3d中,我从相机(彩色相机设备)获取图像作为插件的字节数组,我希望在屏幕上实时显示图像.
如果我用它Texture2D.SetPixels32来制作纹理,它会显着降低fps(从80到10).
//First convert byte[] to color[]
colorr = GetColor(imageBuffer);
imageColor.SetPixels32(colorr);
imageColor.Apply(); // fps reduced here
Run Code Online (Sandbox Code Playgroud)
我想我需要在GPU上使用着色器执行此操作.
那么更快的解决方案是什么?如果回答是使用着色器,可以给出样本.
谢谢.
我有一个c ++ dll,它有一些外部功能.它看起来像这样
//C++ Code
void GetData(byte * pData)
{
byte a[] = {3,2,1};
pData = a;
}
Run Code Online (Sandbox Code Playgroud)
我在C#端使用此代码来获取数据:
//C# Code
[DllImport(UnmanagedDLLAddress)]
public static extern void GetData(ref IntPtr pData);
//and use it like
IntPtr pointer = IntPtr.Zero;
GetData(ref pointer);
byte[] data = new byte[3] // <===== think we know size
Marshal.Copy(pointer,data ,0,3);
Run Code Online (Sandbox Code Playgroud)
但总是"指针"为零所以Marshal.Copy抛出null异常我错了吗?TY