Hi there, 

I'm using the ScreenCaptureHandler to capture a screenshot of the current view 
and save it to disk. I would ideally like to save at a specific resolution, say 
1280x1024, however the handler is saving the image at the current size of the 
viewer. 

My application is a CAD style application so is not full screen. the user is 
free to resize the window and that includes the viewer. Ideally I'd like 
screenshots to be taken at a fixed size and aspect ratio. 

Anyway here's my code. Can anyone suggest what I could do to adjust the 
screenshot size?

BTW - I tried setting the viewport size on the camera but this didn't result in 
a larger image, although it did result in the image appearing to be large 
enough to fit my target size (It was stretched).


Code:

// Create a screen capture handler to capture the screen to image
osg::ref_ptr<osg::Image> capturedImage;
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler = new 
osgViewer::ScreenCaptureHandler();                     

// Create a CWriteToMemoryImageCaptureOperation to get the image out
// NOTE:
// All this does is let me get the image out in memory so I can save it
// What I will eventually do is convert it to .NET Bitmap to pass to 
// other parts of my application
osg::ref_ptr<Native::CWriteToMemoryImageCaptureOperation> writeMem = new 
Native::CWriteToMemoryImageCaptureOperation();

// Set the capture operation on the screenCaptureHandler
screenCaptureHandler->setCaptureOperation(writeMem);

// Capture the next frame
// viewer is the osgviewer instance
screenCaptureHandler->captureNextFrame(*this->viewer);

// 
// Perform a Render Operation
//

// Get the default scene camera
osg::Camera * camera = this->viewer->getCamera();

// Update the camera view/projection matrices
camera->setProjectionMatrixAsPerspective(fieldOfView, aspect, nearClip, 
farClip);
camera->setViewMatrixAsLookAt(GetCameraPosition(), GetCameraTarget(), 
GetUpVector());

// Render the scene
this->viewer->frame();  

// Wait for the captured image to be filled
// NOTE: This really needs to be changed. An event should be raised by
// CWriteToMemoryImageCaptureOperation and passed out to calling code when 
// the image is ready 
while(!capturedImage.valid())
{
        capturedImage = writeMem->GetImage();
}

// TEST:
// Write the image to file
bool success = osgDB::writeImageFile(*capturedImage, "C:\\Apps\\Test.bmp");










Thank you!

Cheers,
Andrew

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=18200#18200





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to