Page 1 of 1

Screenshot

Posted: Fri Mar 07, 2014 4:48 pm
by Victor
Hi,
I need to copy the snapshot to the clipboard. How can I do that in Ogre? Is there any direct Ogre tool for that?
I get the snapshot using the following code:

Code: Select all

	HWND Handle = GetHwnd();

	int Width = GetWindow()->getWidth();
	int Height = GetWindow()->getHeight();

	Ogre::PixelBox * mRenderPixelBox = new Ogre::PixelBox(Width,Height,1,Ogre::PF_A8R8G8B8);
	mRenderPixelBox->data = new BYTE[mRenderPixelBox->getConsecutiveSize()];
	GetWindow()->copyContentsToMemory(*mRenderPixelBox, Ogre::RenderTarget::FB_AUTO);
I copy the snapshot to the clipboard using the following code:

Code: Select all

	OpenClipboard(Handle); 
	EmptyClipboard(); 
	SetClipboardData(CF_BITMAP, mRenderPixelBox->data); 
	CloseClipboard(); 
However applications where I try to paste the bitmap replies that cannot paste the clipboard data.
I also tried this way:

Code: Select all

	BYTE * mTempBufferForSave;
	mTempBufferForSave = new BYTE[mRenderPixelBox->getConsecutiveSize()];
     
   size_t biBitCount = Ogre::PixelUtil::getNumElemBits(mRenderPixelBox->format);
	size_t rowLengthInBytes = biBitCount * lWidth / 8;
	BYTE * data = static_cast<BYTE *>(mRenderPixelBox->data);
	for(int i = 0 ; i < height - 1 ; i++ )
	{
		memcpy(&mTempBufferForSave[rowLengthInBytes * (height - i - 1)], &data[rowLengthInBytes * i], rowLengthInBytes);
	}
   
   BITMAPFILEHEADER* bmfh;
   bmfh = (BITMAPFILEHEADER*)mTempBufferForSave;

   BITMAPINFOHEADER* bmih;
   bmih = (BITMAPINFOHEADER*)(mTempBufferForSave+ sizeof(BITMAPFILEHEADER));
   BITMAPINFO* bmi;
   bmi = (BITMAPINFO*)bmih;
   
   void* bits;
   bits = (void*)(mTempBufferForSave+ bmfh->bfOffBits);
   
   HDC hdc = ::GetDC(NULL);
   HBITMAP hbmp = CreateDIBitmap(hdc, bmih, CBM_INIT, bits, bmi, DIB_RGB_COLORS) ;
	
   if(!hbmp) return; 
	OpenClipboard(lHandle); 
	EmptyClipboard(); 
	SetClipboardData(CF_BITMAP, hbmp); 
	CloseClipboard(); 
Although, it pastes just a small square.

Re: Screenshot

Posted: Sun Mar 09, 2014 6:34 am
by areay
Does it need to be to the clipboard? If you just want a screenshot you can use:

Code: Select all

m_pWindow->writeContentsToTimestampedFile("myProject_", ".jpg");
Where m_pWindow is an Ogre::RenderWindow

Re: Screenshot

Posted: Mon Mar 10, 2014 10:47 am
by Victor
Thank you for your recommendation regarding saving the snapshot to the file. However, I would like to copy the snapshot directly to the Windows clipboard.

Re: Screenshot

Posted: Mon Mar 10, 2014 4:41 pm
by c6burns
The second block of code is getting warmer. You need a bitmap image in the clipboard ... more specifically a windows bitmap handle. MSDN is clear about this in its description of CF_BITMAP (that it must be an HBITMAP). I would start here in the MSDN: http://msdn.microsoft.com/en-us/library ... s.85).aspx

And simply start with storing a bitmap to a file until you know you are generating it properly.