PDA

View Full Version : HELP - ActiveX under Visual C++



Unregistered
July 28, 2004, 15:40:47
Hello
I'm trying to use the activeX under VC++. I already make an application that display an image (in live or snap) and have access to its pixels. However if I try to make some image processing algorithms and try to visualize the results nothing happens. For instance if I execute the invert image example under VB it works fine, but under VC++ everthing works except the final step: visualization.

Can you please help me?
The source code that I use:
////////////////////////////////////////
COleVariant lala;



lala = m_cam1.MemoryGetImageData();

long lb[2];
long ub[2];

SAFEARRAY *dataV=lala.parray;

ASSERT(dataV!=NULL);

unsigned char *erabom;

SafeArrayGetLBound(dataV,1,lb);
SafeArrayGetLBound(dataV,2,lb+1);
SafeArrayGetUBound(dataV,1,ub);
SafeArrayGetUBound(dataV,2,ub+1);
SafeArrayAccessData(dataV, (void **)&erabom);



double s=0.0;
for ( long i=lb[0]; i<ub[0]*ub[1]; i++)
erabom[i]=255-erabom[i];

SafeArrayUnaccessData(dataV);
m_cam1.MemoryReleaseImageData(&lala);

m_cam1.Display();
////////////////////////////////////////

Tim Cassens
July 29, 2004, 14:23:35
The code you posted does not work for me, too. But with IC Imaging Control 2.0, there is a new function in the image buffer allowing you to get the pointer to the image data.

With this function, you can program the access easier:



// Get the index of the last buffer written to
long bufferIndex = m_IC.GetImageBuffers().GetCurrentIndex();

// Get the buffer
CImageBuffer buffer = m_IC.GetImageBuffers().GetItem( bufferIndex );

// Loch the buffer while we operate on it
buffer.Lock();

// Get a pointer to the pixel data
BYTE* pData = (BYTE*)buffer.GetImageDataPtr();

// Invert the image
int count = buffer.GetLines() * buffer.GetPixelPerLine() * 3; // Assuming 24bpp
for( int i = 0; i < count; ++i )
{
*pData = 255 - *pData;
++pData;
}

buffer.Unlock();

m_IC.DisplayImageBuffer( buffer );