如何从c#中的内存流中获取int指针的数据?

Dex*_*ers 1 c# pointers tiff memorystream

我正在使用API​​,并且方法会将图像存储到内存流中,但该方法返回的值是指向内存流的Integer指针和大小值.c#是否支持使用指针进行C风格的内存操作?

如何从内存指针获取图像并将其保存到文件流或另存为文件?有人可以参考这个指针吗?

Ash*_*ore 5

您可以像这样读取内存流:

using (System.IO.UnmanagedMemoryStream memoryStream = new UnmanagedMemoryStream(pointer, length, length, FileAccess.Read))
{
    byte[] imageBytes = new byte[length];
    memoryStream.Read(imageBytes, 0, length);
}
Run Code Online (Sandbox Code Playgroud)

然后解析字节以创建新图像或任何您需要的图像.