• (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

Win32 WebCam Program Displays a Webcam Picture, Saves it as a .bmp file Rate Topic: ***** 4 Votes

#31 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,517
  • Joined: 23-August 08

Posted 28 April 2012 - 11:20 AM

View Posttau_neutrino, on 26 April 2012 - 06:56 PM, said:

View Posttau_neutrino, on 24 April 2012 - 10:44 AM, said:

MOD EDIT: We do NOT support keylogging or spy applications or other malicious activity, even if it *IS* open source.


WOW! Why is that? It is really open source with new FreeBSD license. This can help other people write their code! I wrote it just for fun and learning some winapi of video capture. You see there are people who need this.


The "people who NEED this" are the fucking scumbag script kiddies and organized crime douchenozzles that make software like this required. Don't be fucking daft.
Was This Post Helpful? 2
  • +
  • -

#32 Tim Sloane  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 27-August 12

Posted 29 August 2012 - 10:54 AM

Instead of copying the include and library files, I modified the "Additional Include Directories" and "Additional Library Directories" to also have the original directories where the Win SDK files are found. That also works.
Was This Post Helpful? 0
  • +
  • -

#33 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1345
  • View blog
  • Posts: 4,631
  • Joined: 19-February 09

Posted 19 October 2012 - 06:46 PM

Good tutorial!
Hi, a note for future, when newlines are added to paragraphs they can look jagged on other displays.

Attempt to reproduce :

This WebCam Tutorial will guide you through connecting a webcam in Microsoft Windows and grabbing a frame from the camera so we can later
save it to a bitmap file called "Frame.bmp".
First of all this is a c++ win32 Tutorial so create an empty Win32 application.

This post has been edited by #define: 19 October 2012 - 06:53 PM

Was This Post Helpful? 0
  • +
  • -

#34 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 777
  • View blog
  • Posts: 2,297
  • Joined: 20-March 10

Posted 22 October 2012 - 11:15 AM

@ define,

Ok I will take that on board
but it was a while ago I wrote that tutorial
and I was just really a raw rookie
when I came up with that program.

but thanks for the review.

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#35 Netbug123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 13

Posted 16 January 2013 - 12:49 PM

Hi Snoopy,

Could you let me know what needs to be done if i need to use your code to capture multiple images?

Also, one problem that I am facing with this code is, not everytime when I run the code, the video will be displayed on start camera option. It shows a blank black screen at times. But sometimes, it works fine. Any specific reason for this problem? I am using code blocks.
Was This Post Helpful? 0
  • +
  • -

#36 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 777
  • View blog
  • Posts: 2,297
  • Joined: 20-March 10

Posted 16 January 2013 - 02:19 PM

View PostNetbug123, on 16 January 2013 - 07:49 PM, said:

Hi Snoopy,

Could you let me know what needs to be done if i need to use your code to capture multiple images?

Also, one problem that I am facing with this code is, not everytime when I run the code, the video will be displayed on start camera option. It shows a blank black screen at times. But sometimes, it works fine. Any specific reason for this problem? I am using code blocks.


Its an old api and under Win 7 has some problems it was originally developed for XP on PC's
I am working on a new webcam program that uses the latest api you will have to wait until I
expose this tutorial.

However I have found that while the program has problems running from the IDE under Win7 it has no
problems under release that is build it as an .exe and run it from there.

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#37 Netbug123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 13

Posted 16 January 2013 - 02:38 PM

View Postsnoopy11, on 16 January 2013 - 02:19 PM, said:

View PostNetbug123, on 16 January 2013 - 07:49 PM, said:

Hi Snoopy,

Could you let me know what needs to be done if i need to use your code to capture multiple images?

Also, one problem that I am facing with this code is, not everytime when I run the code, the video will be displayed on start camera option. It shows a blank black screen at times. But sometimes, it works fine. Any specific reason for this problem? I am using code blocks.


Its an old api and under Win 7 has some problems it was originally developed for XP on PC's
I am working on a new webcam program that uses the latest api you will have to wait until I
expose this tutorial.

However I have found that while the program has problems running from the IDE under Win7 it has no
problems under release that is build it as an .exe and run it from there.

Snoopy.





Thank you for ur response. I will try with .exe. and do u have any thoughts on how I could use this to capture multiple images ( 3 or 4).
Was This Post Helpful? 0
  • +
  • -

#38 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 777
  • View blog
  • Posts: 2,297
  • Joined: 20-March 10

Posted 16 January 2013 - 11:39 PM

by images do you mean bitmaps ?
Was This Post Helpful? 0
  • +
  • -

#39 Netbug123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 13

Posted 17 January 2013 - 07:11 AM

View Postsnoopy11, on 16 January 2013 - 11:39 PM, said:

by images do you mean bitmaps ?



Yes. Right now we are able to save just one bitmap image for a grab. Is there a way I can grab continuous images (around 3) n save them separately instead of overwriting on frame.bmp?
Was This Post Helpful? 0
  • +
  • -

#40 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 777
  • View blog
  • Posts: 2,297
  • Joined: 20-March 10

Posted 17 January 2013 - 07:54 AM

Hi,
Yes you can set up a timer
And take pictures at a predermined
Interval.

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#41 Netbug123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 13

Posted 19 January 2013 - 10:32 PM

Hi Snoopy,

Is there any way to preview the captured bitmap image before saving it?
Was This Post Helpful? 0
  • +
  • -

#42 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 777
  • View blog
  • Posts: 2,297
  • Joined: 20-March 10

Posted 20 January 2013 - 08:24 AM

View PostNetbug123, on 20 January 2013 - 05:32 AM, said:

Hi Snoopy,

Is there any way to preview the captured bitmap image before saving it?


Yes just blit it to the window..

I would use StretchBlt for this then you can size it to like a thumbnail..

Snoopy.
Was This Post Helpful? 1
  • +
  • -

#43 Netbug123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 13

Posted 29 January 2013 - 08:20 AM

Hi Snoopy,
Thanks a lot for all the help. I'm able to preview the 2 consecutive captured bitmap images using the code. But as you can see in the code below (bold part), when I use WM_CAP_FILE_SAVEDIB for two different images, only the latest image gets saved in both. I'm trying to solve this problem but could not find any solution. Could you please help me on how I can save both the bitmaps which are in the "curFrame" and "lasFrame" HBITMAP objects?

case 3:
{
//Grab a Frame
SendMessage(camhwnd, WM_CAP_GRAB_FRAME, 0, 0);
//Copy the frame we have just grabbed to the clipboard
SendMessage(camhwnd, WM_CAP_EDIT_COPY,0,0);
//Copy the clipboard image data to a HBITMAP object called curFrame
if (OpenClipboard(camhwnd))
{
if (curFrame != NULL) {
lasFrame = curFrame;

}
curFrame = (HBITMAP) GetClipboardData(CF_BITMAP);
CloseClipboard();
}

InvalidateRect(hwnd,NULL,true); // tell the window it needs to redraw (sends a WM_PAINT message)

.
.
.
.
.
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC screen = BeginPaint(hwnd,&ps);
if (lasFrame != NULL) {
bufFrame = (HBITMAP)SelectObject(hdcMem, lasFrame);
SelectObject(hdcMem, lasFrame);
StretchBlt(screen, // destination DC
180, // x upper left
600, // y upper left
300, // destination width
225, // destination height
hdcMem, // you just created this above
0,
0, // x and y upper left
640, // source bitmap width
480, // source bitmap height
SRCCOPY); // raster operation
LPSTR filename1 =(LPSTR)"Image1.bmp";
SendMessage(camhwnd,WM_CAP_FILE_SAVEDIB, 0, (LPARAM) filename1);

}
bufFrame = (HBITMAP)SelectObject(hdcMem, curFrame);
SelectObject(hdcMem, curFrame);
StretchBlt(screen, // destination DC
520, // x upper left
600, // y upper left
300, // destination width
225, // destination height
hdcMem, // you just created this above
0,
0, // x and y upper left
640, // source bitmap width
480, // source bitmap height
SRCCOPY); // raster operation

LPSTR filename2 =(LPSTR)"Image2.bmp";
SendMessage(camhwnd,WM_CAP_FILE_SAVEDIB, 0, (LPARAM) filename2);


Looking forward to your reply.

Thanks!




View Postsnoopy11, on 20 January 2013 - 08:24 AM, said:

View PostNetbug123, on 20 January 2013 - 05:32 AM, said:

Hi Snoopy,

Is there any way to preview the captured bitmap image before saving it?


Yes just blit it to the window..

I would use StretchBlt for this then you can size it to like a thumbnail..

Snoopy.

Was This Post Helpful? 0
  • +
  • -

#44 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 777
  • View blog
  • Posts: 2,297
  • Joined: 20-March 10

Posted 03 February 2013 - 03:59 AM

Hi,

As I said before use Timers.

something like this

were you set up two timers at different intervals

and save two different images into two different files...


#include <windows.h>
#include <vfw.h>
//Remember to Link to vfw32 Library, gdi32 Library

#define IDT_TIMER1 101
#define IDT_TIMER2 103


LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp);
void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC);

char szAppName [] = TEXT("WebCam");
HWND camhwnd;
HDC hdc ;
HDC hdcMem;
PAINTSTRUCT ps;
HBITMAP hbm;
RECT rc;

//WinMain -- Main Window
int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow )
{

	HWND hwnd;
	MSG msg;

	WNDCLASS wc;
	wc.style = CS_HREDRAW|CS_VREDRAW;
	wc.lpfnWndProc = WindowProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(GetModuleHandle(NULL), IDI_APPLICATION);
	wc.hCursor = LoadCursor (NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = szAppName;

	RegisterClass (&wc);

	// Create the window
	hwnd = CreateWindow (szAppName,szAppName,WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,CW_USEDEFAULT,CW_USEDEFAULT,300,600,0,0,hInstance,0);

	ShowWindow (hwnd,SW_SHOW);
	UpdateWindow (hwnd);

	while (GetMessage(&msg,0,0,0))
	{
		if (!IsDialogMessage(hwnd, &msg))
		{
			TranslateMessage (&msg);
			DispatchMessage (&msg);
		}
	}
	return msg.wParam;
}

//Main Window Procedure WindowProc
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HINSTANCE hInstance = GetModuleHandle(NULL);

	//some buttons
	HWND hButtStartCam;
	HWND hButtStopCam;
	HWND hButtGrabFrame;

	switch (message)                  /* handle the messages */
	{

	case WM_CTLCOLORSTATIC:
		SetBkMode(hdc,TRANSPARENT);
		return (LRESULT)CreateSolidBrush(0xFFFFFF);

	case WM_CREATE:
		{
			hButtStartCam = CreateWindowEx(0,"BUTTON","Start Camera",WS_CHILD | WS_VISIBLE,
				0,0,100,20,hwnd,(HMENU)1,hInstance, 0);
			hButtStopCam = CreateWindowEx(0,"BUTTON","Stop Camera",WS_CHILD | WS_VISIBLE,
				0,25,100,20,hwnd,(HMENU)2,hInstance, 0);
			hButtGrabFrame = CreateWindowEx(0,"BUTTON","Grab Frame",WS_CHILD | WS_VISIBLE,
				0,50,100,20,hwnd,(HMENU)3,hInstance, 0);

			camhwnd = capCreateCaptureWindow ("camera window", WS_CHILD , 0, 100, 300, 300, hwnd, 1001);
			SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);
			SendMessage(camhwnd,WM_CAP_DLG_VIDEOSOURCE,0,0);


			break;
		}
	case WM_TIMER: 
		PBITMAPINFO pbi1;
		PBITMAPINFO pbi2;
		switch (wParam) 
		{ 
		case IDT_TIMER1: 
			{
				// process the 10-second timer 
				//Grab a Frame
				SendMessage(camhwnd, WM_CAP_GRAB_FRAME, 0, 0);
				//Copy the frame we have just grabbed to the clipboard
				SendMessage(camhwnd, WM_CAP_EDIT_COPY,0,0);

				//Copy the clipboard image data to a HBITMAP object called hbm
				hdc = BeginPaint(camhwnd, &ps);
				hdcMem = CreateCompatibleDC(hdc);
				if (hdcMem != NULL)
				{
					if (OpenClipboard(camhwnd))
					{
						hbm = (HBITMAP) GetClipboardData(CF_BITMAP);
						SelectObject(hdcMem, hbm);
						GetClientRect(camhwnd, &rc);
						CloseClipboard();
					}
				}
				//Save hbm to a .bmp file called Frame.bmp
				pbi1 = CreateBitmapInfoStruct(hwnd, hbm);
				CreateBMPFile(hwnd, "Frame1.bmp", pbi1, hbm, hdcMem);

				SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);
				SendMessage(camhwnd, WM_CAP_SET_SCALE, true , 0);
				SendMessage(camhwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);
				SendMessage(camhwnd, WM_CAP_SET_PREVIEW, true , 0);

				break; 
			}
		case IDT_TIMER2: 
			{
				// process the fifteen second timer 
				//Grab a Frame
				SendMessage(camhwnd, WM_CAP_GRAB_FRAME, 0, 0);
				//Copy the frame we have just grabbed to the clipboard
				SendMessage(camhwnd, WM_CAP_EDIT_COPY,0,0);

				//Copy the clipboard image data to a HBITMAP object called hbm
				hdc = BeginPaint(camhwnd, &ps);
				hdcMem = CreateCompatibleDC(hdc);
				if (hdcMem != NULL)
				{
					if (OpenClipboard(camhwnd))
					{
						hbm = (HBITMAP) GetClipboardData(CF_BITMAP);
						SelectObject(hdcMem, hbm);
						GetClientRect(camhwnd, &rc);
						CloseClipboard();
					}
				}
				//Save hbm to a .bmp file called Frame.bmp
				pbi2 = CreateBitmapInfoStruct(hwnd, hbm);
				CreateBMPFile(hwnd, "Frame2.bmp", pbi2, hbm, hdcMem);

				SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);
				SendMessage(camhwnd, WM_CAP_SET_SCALE, true , 0);
				SendMessage(camhwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);
				SendMessage(camhwnd, WM_CAP_SET_PREVIEW, true , 0);

				break;
			}

			break;
		} 
	case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{

			case 1:
				{
					ShowWindow(camhwnd,SW_SHOW);
					SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);
					SendMessage(camhwnd, WM_CAP_SET_SCALE, true , 0);
					SendMessage(camhwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);
					SendMessage(camhwnd, WM_CAP_SET_PREVIEW, true , 0);


					SetTimer(hwnd,             // handle to main window 
						IDT_TIMER1,            // timer identifier 
						10000,                 // 10-second interval 
						(TIMERPROC) NULL);     // no timer callback 

					SetTimer(hwnd,             // handle to main window 
						IDT_TIMER2,            // timer identifier 
						15000,                // 15-second interval 
						(TIMERPROC) NULL);     // no timer callback 
					break;
				}

			case 2:
				{
					ShowWindow(camhwnd,SW_HIDE);
					SendMessage(camhwnd, WM_CAP_DRIVER_DISCONNECT, 0, 0);
					break;
				}

			case 3:
				{
					//Grab a Frame
					SendMessage(camhwnd, WM_CAP_GRAB_FRAME, 0, 0);
					//Copy the frame we have just grabbed to the clipboard
					SendMessage(camhwnd, WM_CAP_EDIT_COPY,0,0);

					//Copy the clipboard image data to a HBITMAP object called hbm
					hdc = BeginPaint(camhwnd, &ps);
					hdcMem = CreateCompatibleDC(hdc);
					if (hdcMem != NULL)
					{
						if (OpenClipboard(camhwnd))
						{
							hbm = (HBITMAP) GetClipboardData(CF_BITMAP);
							SelectObject(hdcMem, hbm);
							GetClientRect(camhwnd, &rc);
							CloseClipboard();
						}
					}
					//Save hbm to a .bmp file called Frame.bmp
					PBITMAPINFO pbi = CreateBitmapInfoStruct(hwnd, hbm);
					CreateBMPFile(hwnd, "Frame.bmp", pbi, hbm, hdcMem);

					SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);
					SendMessage(camhwnd, WM_CAP_SET_SCALE, true , 0);
					SendMessage(camhwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);
					SendMessage(camhwnd, WM_CAP_SET_PREVIEW, true , 0);
					break;
				}
			}
			break;
		}

	case WM_DESTROY:
		{
			SendMessage(camhwnd, WM_CAP_DRIVER_DISCONNECT, 0, 0);
			KillTimer(hwnd,IDT_TIMER1);
			KillTimer(hwnd,IDT_TIMER2);
			PostQuitMessage(0);   /* send a WM_QUIT to the message queue */
			break;
		}

	default:              /* for messages that we don't deal with */
		return DefWindowProc(hwnd, message, wParam, lParam);
	}
	return 0;
}

void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC)
{
	HANDLE hf;                  // file handle
	BITMAPFILEHEADER hdr;       // bitmap file-header
	PBITMAPINFOHEADER pbih;     // bitmap info-header
	LPBYTE lpBits;              // memory pointer
	DWORD dwTotal;              // total count of bytes
	DWORD cb;                   // incremental count of bytes
	BYTE *hp;                   // byte pointer
	DWORD dwTmp;

	pbih = (PBITMAPINFOHEADER) pbi;
	lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

	if (!lpBits)
	{
		MessageBox(hwnd,"GlobalAlloc","Error", MB_OK );
	}
	// Retrieve the color table (RGBQUAD array) and the bits
	// (array of palette indices) from the DIB.
	if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi,DIB_RGB_COLORS))
	{
		MessageBox(hwnd,"GetDIBits","Error",MB_OK );
	}
	// Create the .BMP file.
	hf = CreateFile(pszFile,GENERIC_READ | GENERIC_WRITE,(DWORD) 0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL);
	if (hf == INVALID_HANDLE_VALUE)
	{
		MessageBox( hwnd,"CreateFile","Error", MB_OK);
	}

	hdr.bfType = 0x4d42;  // File type designator "BM" 0x42 = "B" 0x4d = "M"
	// Compute the size of the entire file.
	hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD) + pbih->biSizeImage);
	hdr.bfReserved1 = 0;
	hdr.bfReserved2 = 0;
	// Compute the offset to the array of color indices.
	hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof (RGBQUAD);
	// Copy the BITMAPFILEHEADER into the .BMP file.
	if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), (LPDWORD) &dwTmp,  NULL) )
	{
		MessageBox(hwnd,"WriteFileHeader","Error",MB_OK );
	}
	// Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
	if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD), (LPDWORD) &dwTmp, NULL))
	{
		MessageBox(hwnd,"WriteInfoHeader","Error",MB_OK );
	}
	// Copy the array of color indices into the .BMP file.
	dwTotal = cb = pbih->biSizeImage;
	hp = lpBits;
	if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL))
	{
		MessageBox(hwnd,"WriteFile","Error",MB_OK );
	}
	// Close the .BMP file.
	if (!CloseHandle(hf))
	{
		MessageBox(hwnd,"CloseHandle","Error",MB_OK );
	}

	// Free memory.
	GlobalFree((HGLOBAL)lpBits);
}

PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp)
{
	BITMAP bmp;
	PBITMAPINFO pbmi;
	WORD cClrBits;
	// Retrieve the bitmap color format, width, and height.
	if (!GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp))
	{
		MessageBox(hwnd,"GetObject","Error",MB_OK );
	}
	// Convert the color format to a count of bits.
	cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
	if (cClrBits == 1)
		cClrBits = 1;
	else if (cClrBits <= 4)
		cClrBits = 4;
	else if (cClrBits <= 8)
		cClrBits = 8;
	else if (cClrBits <= 16)
		cClrBits = 16;
	else if (cClrBits <= 24)
		cClrBits = 24;
	else cClrBits = 32;

	// Allocate memory for the BITMAPINFO structure. (This structure
	// contains a BITMAPINFOHEADER structure and an array of RGBQUAD
	// data structures.)

	if (cClrBits != 24)
	{
		pbmi = (PBITMAPINFO) LocalAlloc(LPTR,sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * (1<< cClrBits));
	}
	// There is no RGBQUAD array for the 24-bit-per-pixel format.
	else
		pbmi = (PBITMAPINFO) LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER));

	// Initialize the fields in the BITMAPINFO structure.
	pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	pbmi->bmiHeader.biWidth = bmp.bmWidth;
	pbmi->bmiHeader.biHeight = bmp.bmHeight;
	pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
	pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
	if (cClrBits < 24)
	{
		pbmi->bmiHeader.biClrUsed = (1<<cClrBits);
	}
	// If the bitmap is not compressed, set the BI_RGB flag.
	pbmi->bmiHeader.biCompression = BI_RGB;

	// Compute the number of bytes in the array of color
	// indices and store the result in biSizeImage.
	// For Windows NT, the width must be DWORD aligned unless
	// the bitmap is RLE compressed. This example shows this.
	// For Windows 95/98/Me, the width must be WORD aligned unless the
	// bitmap is RLE compressed.
	pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8 * pbmi->bmiHeader.biHeight;
	// Set biClrImportant to 0, indicating that all of the
	// device colors are important.
	pbmi->bmiHeader.biClrImportant = 0;

	return pbmi; //return BITMAPINFO
}





Best Wishes

Snoopy.
Was This Post Helpful? 1
  • +
  • -

#45 Netbug123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-January 13

Posted 11 February 2013 - 07:46 PM

View Postsnoopy11, on 03 February 2013 - 03:59 AM, said:

Hi,

As I said before use Timers.

something like this

were you set up two timers at different intervals

and save two different images into two different files...

Best Wishes

Snoopy.



Hi Snoopy,

Thanks for the reply and it did help me out. Although, when I made changes to work with WM_CAP_FILE_SAVEDIB directly instead of writing CreateBitmapInfoStruct & CreateBMPFile functions, I am facing problems in saving the file. I have made the specific changes correctly (I think :)) But when i use WM_CAP_FILE_SAVEDIB, same image is being captured in both Frame1 and Frame2. Am I missing something?

Thank you.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4