WK Ho
January 1, 2008, 05:08:18
Hi There
I am trying to access memory buffer after snapping in an image, below is the code I used:
tFrameHandlerSinkPtr pSink=FrameHandlerSink::create( eRGB32, 1 );//create a buf same as grabber
m_Grabber.setSinkType( pSink ); //set the grabbed image to copy to the sink created
pSink->setSnapMode( true );
//FrameTypeInfo info;
//pSink->getOutputFrameType( info );
m_Grabber.startLive( false );
pSink->snapImages(1);
// get pointer to the image data
smart_ptr<MemBuffer> pActiveBuf=pSink->getLastAcqMemBuffer();
// image buffer pixel format is set to eRGB32
/* Copied from sample
RGBQUAD* pbImgData = (RGBQUAD*)pActiveBuf->getPtr();
// Calculate the index of the upper left pixel
// Images are stored upside down in the image buffer
SIZE dim = pActiveBuf->getFrameType().dim;
int iOffsUpperLeft = (dim.cy-1) * dim.cx;
printf( "\nImage buffer pixel format is eRGB32\n" );
printf( "Pixel 1(RGBA): %d %d %d %d\n", pbImgData[iOffsUpperLeft].rgbRed,
pbImgData[iOffsUpperLeft].rgbGreen,
pbImgData[iOffsUpperLeft].rgbBlue,
pbImgData[iOffsUpperLeft].rgbReserved );
printf( "Pixel 2(RGBA): %d %d %d %d\n", pbImgData[iOffsUpperLeft+1].rgbRed,
pbImgData[iOffsUpperLeft+1].rgbGreen,
pbImgData[iOffsUpperLeft+1].rgbBlue,
pbImgData[iOffsUpperLeft+1].rgbReserved );
// overwrite first 3 pixels and save image to disk
// Set the first pixel to RED
pbImgData[iOffsUpperLeft].rgbRed = 0xff;
pbImgData[iOffsUpperLeft].rgbGreen = 0;
pbImgData[iOffsUpperLeft].rgbBlue = 0;
pbImgData[iOffsUpperLeft].rgbReserved = 0;
// Set the second pixel to GREEN
pbImgData[iOffsUpperLeft+1].rgbRed = 0;
pbImgData[iOffsUpperLeft+1].rgbGreen = 0xff;
pbImgData[iOffsUpperLeft+1].rgbBlue = 0;
pbImgData[iOffsUpperLeft+1].rgbReserved = 0;
// Set the third pixel to BLUE
pbImgData[iOffsUpperLeft+2].rgbRed = 0;
pbImgData[iOffsUpperLeft+2].rgbGreen = 0;
pbImgData[iOffsUpperLeft+2].rgbBlue = 0xff;
pbImgData[iOffsUpperLeft+2].rgbReserved = 0;
saveToFileBMP( *pActiveBuf, "RGB32.bmp" );
printf( "Image saved to file \"RGB32.bmp\"\n" );
I can compile it without error, however, when I run the program and it gives at the statement :
RGBQUAD* pbImgData = (RGBQUAD*)pActiveBuf->getPtr();
First-chance exception in CaptureTest.exe: 0xC0000005: Access Violation.
Before execute to the problem statemnt I get a message :
c:\csource\ic30\core\dshowlib\filtergraph.cpp(301) : Graph returned S_FALSE, so not yet started ...
What is the above message means?
Is it because the snap was fail and causes the error ?
I can view the dispalyed image before I try to snap in the image on the same program.
Thanks for your help.
I am trying to access memory buffer after snapping in an image, below is the code I used:
tFrameHandlerSinkPtr pSink=FrameHandlerSink::create( eRGB32, 1 );//create a buf same as grabber
m_Grabber.setSinkType( pSink ); //set the grabbed image to copy to the sink created
pSink->setSnapMode( true );
//FrameTypeInfo info;
//pSink->getOutputFrameType( info );
m_Grabber.startLive( false );
pSink->snapImages(1);
// get pointer to the image data
smart_ptr<MemBuffer> pActiveBuf=pSink->getLastAcqMemBuffer();
// image buffer pixel format is set to eRGB32
/* Copied from sample
RGBQUAD* pbImgData = (RGBQUAD*)pActiveBuf->getPtr();
// Calculate the index of the upper left pixel
// Images are stored upside down in the image buffer
SIZE dim = pActiveBuf->getFrameType().dim;
int iOffsUpperLeft = (dim.cy-1) * dim.cx;
printf( "\nImage buffer pixel format is eRGB32\n" );
printf( "Pixel 1(RGBA): %d %d %d %d\n", pbImgData[iOffsUpperLeft].rgbRed,
pbImgData[iOffsUpperLeft].rgbGreen,
pbImgData[iOffsUpperLeft].rgbBlue,
pbImgData[iOffsUpperLeft].rgbReserved );
printf( "Pixel 2(RGBA): %d %d %d %d\n", pbImgData[iOffsUpperLeft+1].rgbRed,
pbImgData[iOffsUpperLeft+1].rgbGreen,
pbImgData[iOffsUpperLeft+1].rgbBlue,
pbImgData[iOffsUpperLeft+1].rgbReserved );
// overwrite first 3 pixels and save image to disk
// Set the first pixel to RED
pbImgData[iOffsUpperLeft].rgbRed = 0xff;
pbImgData[iOffsUpperLeft].rgbGreen = 0;
pbImgData[iOffsUpperLeft].rgbBlue = 0;
pbImgData[iOffsUpperLeft].rgbReserved = 0;
// Set the second pixel to GREEN
pbImgData[iOffsUpperLeft+1].rgbRed = 0;
pbImgData[iOffsUpperLeft+1].rgbGreen = 0xff;
pbImgData[iOffsUpperLeft+1].rgbBlue = 0;
pbImgData[iOffsUpperLeft+1].rgbReserved = 0;
// Set the third pixel to BLUE
pbImgData[iOffsUpperLeft+2].rgbRed = 0;
pbImgData[iOffsUpperLeft+2].rgbGreen = 0;
pbImgData[iOffsUpperLeft+2].rgbBlue = 0xff;
pbImgData[iOffsUpperLeft+2].rgbReserved = 0;
saveToFileBMP( *pActiveBuf, "RGB32.bmp" );
printf( "Image saved to file \"RGB32.bmp\"\n" );
I can compile it without error, however, when I run the program and it gives at the statement :
RGBQUAD* pbImgData = (RGBQUAD*)pActiveBuf->getPtr();
First-chance exception in CaptureTest.exe: 0xC0000005: Access Violation.
Before execute to the problem statemnt I get a message :
c:\csource\ic30\core\dshowlib\filtergraph.cpp(301) : Graph returned S_FALSE, so not yet started ...
What is the above message means?
Is it because the snap was fail and causes the error ?
I can view the dispalyed image before I try to snap in the image on the same program.
Thanks for your help.