[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

3.8

How Display bitmap data (a variable, not a file)  into a Picture Box with MFC or WIN32 ?

Asked by Develprog in Windows MFC Programming, Windows Programming, C++ Programming Language

Hello,
Here is my first post, so I made an application using HBITMAP with the LoadImage method () on a bmp file. But this time I would load an image, not from a file (code below) but using data in memory (see comments).

My program works like a wrapper class by calling a main class named Camdev , this class saves a bitmap file on disk -and my application used HBITMAP LoadImage() to display each image from the camera in the Picture box.
I used the code bellow and that works perfect.

But the Camdev class also has a method that saves in memory (SaveToMem ()). I don't want to save the file on disk, so I 'll save the bitmap in a memory buffer then how do it I heard about using LoadImage with parameter LR_CREATEDIBSECTION but how implement that ?

The MFC LoadBitmap() function does only load bitmaps from resource in VC++ so I decided to use LoadImage() but I don't know how?

How do I pass the bitmap data buffer so my fonctions GetcaptureImage () and DisplayImage () use this data properly with MFC or Win API methods ?



Thank you


Here's the code:
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;
}
 
Related Solutions
 
Loading Advertisement...
 
[+][-]09/11/09 09:20 AM, ID: 25311009Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/13/09 09:52 AM, ID: 25320917Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09/13/09 09:53 AM, ID: 25320922Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09/13/09 10:20 AM, ID: 25321036Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/13/09 10:24 AM, ID: 25321063Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/13/09 10:28 AM, ID: 25321076Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/13/09 10:32 AM, ID: 25321092Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/13/09 10:40 PM, ID: 25323066Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/13/09 10:55 PM, ID: 25323100Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/13/09 11:05 PM, ID: 25323122Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/13/09 11:07 PM, ID: 25323128Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 12:26 AM, ID: 25323374Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 12:45 AM, ID: 25323427Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 12:56 AM, ID: 25323465Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 01:01 AM, ID: 25323491Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 01:04 AM, ID: 25323501Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 01:13 AM, ID: 25323532Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 03:12 AM, ID: 25324004Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 03:15 AM, ID: 25324021Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 04:32 AM, ID: 25324431Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 04:44 AM, ID: 25324483Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 05:14 AM, ID: 25324615Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 05:47 AM, ID: 25324814Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 06:09 AM, ID: 25324981Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 07:06 AM, ID: 25325540Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 07:26 AM, ID: 25325771Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 09:39 AM, ID: 25327119Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/15/09 12:01 AM, ID: 25332385Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/15/09 12:04 AM, ID: 25332395Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/15/09 12:06 AM, ID: 25332408Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/15/09 12:19 AM, ID: 25332490Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/15/09 12:37 AM, ID: 25332600Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/15/09 12:49 AM, ID: 25332654Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/15/09 01:45 AM, ID: 25332962Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/15/09 02:35 AM, ID: 25333213Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/15/09 06:50 AM, ID: 25334837Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/15/09 06:58 AM, ID: 25334906Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/15/09 11:08 PM, ID: 25342369Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/16/09 03:54 AM, ID: 25344059Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Windows MFC Programming, Windows Programming, C++ Programming Language
Sign Up Now!
Solution Provided By: Develprog
Participating Experts: 2
Solution Grade: A
 
[+][-]09/16/09 06:50 AM, ID: 25345528Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/17/09 09:59 AM, ID: 25358378Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/17/09 10:32 AM, ID: 25358792Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625