1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
|
//Capture Image from file (loadimage)
//
#include "stdafx.h"
#include "Cam_conf.h"
#include "Cam_confDlg.h"
HWND hwnd = NULL;
Camdev cp; //class
HBITMAP eventsavedlgdc = (HBITMAP)::LoadImage(NULL,"readframes01.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
HDC hMemDC;
RECT rectScaled;
int rectW;
int rectH;
void CAboutDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rc( 0, 0, 4, 8 );
MapDialogRect( &rc );
int baseUnitY = rc.bottom;
int baseUnitX = rc.right;
TRACE("baseUnitX = %d\n", baseUnitX);
TRACE("baseUnitY = %d\n", baseUnitY);
TRACE("Dans OnPaint\n"); //ajout
}
CCam_confDlg::~CCam_confDlg() //
{
if (m_Picture)::DeleteObject(m_Picture);
if (Bmp4.m_hObject)::DeleteObject(Bmp4.m_hObject);
m_Font.DeleteObject();
cp.StopCapture();
cp.SaveSettingsToFile();//
}
BOOL CCam_confDlg::OnInitDialog()
{
//Set the icon for this dialog. The framework does this automatically
//when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); //Set big icon
SetIcon(m_hIcon, FALSE);//Set small icon
//dimensions of the control
m_Picture.GetWindowRect(&rectScaled);
rectW=rectScaled.right-rectScaled.left;
rectH=rectScaled.bottom-rectScaled.top;
store=cp.Init(Gl_ip); // utiliser l'addresse IP de l'argument
SetTimer(ID_TIMER1, 90, 0);
}
void CCam_confDlg::OnTimer(UINT nIDEvent)
{
CDialog::OnTimer(nIDEvent);
if (nIDEvent ==ID_TIMER1)
{
TRACE("ON_TIMER_IN\n");
UpdateData(TRUE);
//KillTimer(1);
KillTimer(ID_TIMER1);
//MUTEX
if(!GetCaptureImage())
{
cm_display.Lock(); //Mutex
if(!DisplayImage()) ;
cm_display.Unlock();//Mutex
}
SetTimer(ID_TIMER1,10,0);
UpdateData(FALSE);
}
}
bool CCam_confDlg::GetCaptureImage()
{
if(!cp.GetCaptureInfo(&status, &newestframeix, &newesttimems,
&nframes, &nprocbufs, &nusable, &nlocked, lockitems, &nlockitems))
{
gx_geterror(&ecode, ebuf, sizeof(ebuf));
return TRUE;
}
// Lock frame
if(!cp.LockFrames(FXCAM_LOCK_RELEASE_ALL_OTHER, frame, frame))
{
// Error occurred
return TRUE;
}
// Read frame
if(!cp.ReadFrame(FXCAM_READFRAME_AUTOADJUST, 0, frame, NULL, &frametimems, &newestframeix, NULL, cp.image))
{
if(nlockitems == 0)
{
// Error occurred
return TRUE;
}
}
// Release the locked frame
if(!cp.UnlockFrames(0, frame, frame))
{
// Error occurred
return TRUE;
}
//save image //Utiliser SavetoMem vers ppm (pour stream), vers jpg (pour snapshot)
if(!cp.image.Save("readframes01.bmp", GX_BMP))
{
gx_geterror(&ecode, ebuf, sizeof(ebuf));
return TRUE;
}
capture_ok=true;
return FALSE;
}
bool CCam_confDlg::DisplayImage()
{
capture_ok=false;
if (eventsavedlgdc)
{
::DeleteObject(eventsavedlgdc);
}
eventsavedlgdc = (HBITMAP)::LoadImage(NULL,"readframes01.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);//OK
CBitmap bmp;
bmp.Attach(eventsavedlgdc);
BITMAP bm;
bmp.GetBitmap(&bm);
bmp.Detach();
HDC hdc=::GetDC(m_Picture.m_hWnd);
HDC memdc=::CreateCompatibleDC(hdc);
HBITMAP hBmp2=(HBITMAP)SelectObject(memdc,eventsavedlgdc);
SetStretchBltMode(hdc,COLORONCOLOR); //For better quality
StretchBlt(hdc,0,0,rectW,rectH,memdc,0,0,752,480,SRCCOPY);
DeleteDC(hdc);
DeleteDC(memdc);
if(eventsavedlgdc)
{
m_Picture.SetBitmap(hBmp2);
DeleteDC(hMemDC);
DeleteObject(eventsavedlgdc);
}
capture_ok=true;
return FALSE;
}
|