Screenshot

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
Victor
Gnoblar
Posts: 7
Joined: Wed Dec 11, 2013 1:19 pm

Screenshot

Post 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.
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Screenshot

Post 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
Victor
Gnoblar
Posts: 7
Joined: Wed Dec 11, 2013 1:19 pm

Re: Screenshot

Post 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.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Screenshot

Post 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.
Post Reply