PDA

View Full Version : displaying a smaller window of a live stream



Thomas
November 12, 2014, 00:27:12
Hello,

I've been using the double buffer example and I would like to show a smaller window,
I've set the window size with m_pGrabber->setWindowSize but the window still displays
the top left portion, but I'm trying to display it centered. Here is my ::DrawBuffer.



void CListener::DrawBuffer( Grabber& grabber, smart_ptr<MemBuffer> pBuffer)
{
long posx;
long posy;
long width;
long height;

if( m_pDrawWindow != NULL && pBuffer != NULL)
{
grabber.getWindowPosition (posx, posy, width, height);

smart_ptr<BITMAPINFOHEADER> pInf = pBuffer->getBitmapInfoHeader();
void* pBuf = pBuffer->getPtr();
HDC hDC = GetDC( m_pDrawWindow->GetSafeHwnd());
if( m_memDC == NULL )
{
m_memDC = CreateCompatibleDC(hDC);
SetStretchBltMode(m_memDC , COLORONCOLOR);
// Select the bitmap of the memory DC to draw in.
SelectObject(m_memDC, m_hCameraBitmap);
}


SetStretchBltMode(hDC , COLORONCOLOR);

// Now perform the drawings
int nLines = StretchDIBits(m_memDC,// Handle to the device
posx, // x-coord of destination upper-left corner
posy, // y-coord of destination upper-left corner
width, // width of destination rectangle
height, // height of destination rectangle
0, // x-coord of source upper-left corner
0,// y-coord of source upper-left corner
pInf->biWidth, // Source rectangle width
pInf->biHeight, // Source rectangle height
pBuffer->getPtr(), // Modified address of array with DIB bits0, // First scan line in array
reinterpret_cast<LPBITMAPINFO>( &*pInf ),
DIB_RGB_COLORS,// RGB or palette indices
SRCCOPY
);

DoDrawings (pBuffer); // Do some drawings on the video frame.

// Copy the complete drawing to the hDC so it can be seen on the window.
BitBlt( hDC,0,0,m_cCameraRect.Width(), m_cCameraRect.Height(),
m_memDC,0,0, SRCCOPY);

ReleaseDC(grabber.getHWND(),hDC);
}
}


Any help would be greatly appreciated.

Thanks,
Thomas

Stefan Geissler
November 12, 2014, 11:17:37
Hello

grabber.getWindowPosition (posx, posy, width, height);

wont help, because you need the Window's size, you want to draw in.

http://msdn.microsoft.com/de-de/library/windows/desktop/ms633503%28v=vs.85%29.aspx

Rect rect;
GetClientRect( grabber.getHWND(), &rect );

BTW: Now I understand your flickerfree drawing post.

If you want this flicker free, then you need to create a HBITMAP in memory. On this you draw the camera image, then your lines and text and then you bitblit() or stretchblt() it on the drawing windown

Thomas
January 15, 2015, 19:27:29
Hi Stefan,

Once I have my view window say 240 x 320 and my camera is 480 x 640. Would
I use grabber.setWindowPosition (-120, -160, 640, 480); to have the camera view
centered in my view window?

Thanks,
Thomas

Thomas
January 16, 2015, 06:37:18
Hi,

I'm still trying to figure out how to center this window. Say my ClientRect is 320x240 and my camera is 640x480. How
would I center the camera in the client?

Thanks,
Thomas

Thomas
January 16, 2015, 06:37:39
Hi,

I'm still trying to figure out how to center this window. Say my ClientRect is 320x240 and my camera is 640x480. How
would I center the camera in the client?

Thanks,
Thomas

Stefan Geissler
January 16, 2015, 09:25:21
Hello


Once I have my view window say 240 x 320 and my camera is 480 x 640. Would
I use grabber.setWindowPosition (-120, -160, 640, 480); to have the camera view
centered in my view window?
Yes. But you also must call
grabber.setDefaultWindowPosition(false);
Otherwise setWindowPosition () has no effect.