如何从指向一系列内存的指针指针获取数据地址? [英] how to get the data address from a pointer pointer which point to a series of memory?

查看:200
本文介绍了如何从指向一系列内存的指针指针获取数据地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我这里有一个非常紧急的问题,过去三天我无法解决。它可以简化如下:

Hi everyone, here I have a problem which is very urgent and I couldn''t resolve during the past three days. It can be simplified as below:

typedef struct _tagBufferStatus
{
      long BufferCount;
      byte** Buffer;
       ...
}StructBufferStatus;
        int nIndex = 0;
        byte *pIn;
        BITMAPFILEHEADER bmfHdr;
        BITMAPINFOHEADER bmiHdr;
        LPBITMAPIINFO lpbmi;
	StructCurrentImageSize structCurImg = MS_GetCurrentImageSize(g_CameraID,&status);
	int cxWidth  = structCurImg.ImageWidthFromCamera;
	int cyHeight = structCurImg.ImageHeightFromCamera;
	DWORD memSize = cxWidth*cyHeight;
	byte *pOut= new byte[memSize];
	ZeroMemory(pOut,memSize);
	LPBITMAPINFO lpbmi;
	DWORD BitmapInfoSize;
	MS_CreateDIBHeader(g_CameraID,&lpbmi,&BitmapInfoSize,&status);
	DWORD dwSize = lpbmi->bmiHeader.biSizeImage;
	static StructBufferStatus  structBufStatus = MS_GetBufferStatus(g_CameraID,&status);
	StructCaptureStatus structCapStatus = MS_GetCaptureStatus(g_CameraID,&status);
	nIndex = structBufStatus.LastValidFrame;
	byte **pTemp = structBufStatus.ImageBuffers;
	pIn = pTemp[nIndex];
	MS_GetGrayscaleImage(g_CameraID,pIn,pOut,&status);
        
        bmfHdr.bfOffBits   = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD);
	bmfHdr.bfReserved1 =0;
	bmfHdr.bfReserved2 =0;
	bmfHdr.bfSize = memSize +sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD);
	bmfHdr.bfType = 0x4d42;
        memcpy(&bmiHdr,lpbmi,sizeof(BITMAPINFOHEADER));
        SavetoBMP(bmfHdr,bmiHdr,pOut);



在这种情况下,函数 StructImageBuffer GetImageBuffer(long CameraID)是为检索指向一系列图像缓冲区的指针的目的。由于每个图像缓冲区都由指针表示,我们需要一个指针指针来获取图像缓冲区序列的起始地址。

使用函数 GetImage(long CameraID,byte * pSrc,byte * pDst )将图像数据存储在pDst中,其中pSrc指向图像缓冲区系列中的一个图像缓冲区。



这里,问题是:这两个函数由DLL提供,ImageBuffer由DLL保留,我无法将数据从Buffer复制到pDst。是否有人遇到过同样的问题并且善意地帮我一把?所有的谢谢!


In this case, function StructImageBuffer GetImageBuffer(long CameraID) is provided for the purpose of retrieving a pointer to a series of image buffer. As each image buffer is represented by a pointer,we need a pointer pointer to get the starting address of image buffer series.
use functionGetImage(long CameraID,byte *pSrc,byte *pDst) to store an image data in pDst, where pSrc points to one of the image buffer in the image buffer series.

here,the problem is : the two functions is provdied by DLL,and ImageBuffer is reserved by DLL,and I can''t copy data from Buffer to pDst. Is there anyone who has encountered the same problem and is kindly enough to give me a hand? All the thanks!

推荐答案

除了你在struct中一直遗漏r这一事实外,有几件事情看起来很奇怪。您展示的代码甚至无法编译。



查看库供应商的文档,看看GetImageBuffer是否真的返回了StructImageBuffer!这个结构可以有相当大的尺寸,并且不太可能有人将其作为结果值传递。



如果GetImageBuffer确实返回了StructImageBuffer,为什么需要一个GetImage函数?您可以通过从StructImageBuffer检索缓冲区指针来访问图像。



GetImage函数将CameraId作为第一个参数。如果图像数据已经驻留在pSrc指向的缓冲区中,那是没有意义的。



我认为你误解了供应商的描述这两个函数很难猜到它们真正做了什么。



顺便说一句:图像缓冲区中的值通常看起来不像乱七八糟,但是只是图像的像素数据。在调试器中将它们看作hex或int值,它们应该有意义。
There are several things that look weird here, besides the fact that you consistently left out the "r" in "struct". The code you showed would not even compile.

Take a look into the documentation of your library vendor and see whether GetImageBuffer really returns a StructImageBuffer! This structure can have a considerable size and it is unlikely that someone passes that as a result value.

If GetImageBuffer really returns a StructImageBuffer, why would one need a GetImage function? You could simply access the image by retrieving the buffer pointer from the StructImageBuffer.

The GetImage function takes the CameraId as first argument. That doesn''t make sense if the image data already reside in the buffer pointed to by pSrc.

I think that you have misinterpreted the vendor''s description of the two functions and it is hard to guess what they really do.

Btw.: The values in an image buffer do normally not look like "a mess", but are simply the pixel data of the image. Look at them in your debugger as hex or int values and they should make sense.


在调试时保存为BMP文件之前,是否在pDst中获得了有效值?
Are you getting valid values in the pDst before saving as BMP file while you debug?


这篇关于如何从指向一系列内存的指针指针获取数据地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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