|
Below is the code snippet I wrote for displaying pixel values onto the screen in MFC. The pixel values are stored in buffer disp_frame. But nothing appears on screen. Could anyone debug this code.
void CBluetooth_decoderDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int p=0,i=0,j=0,q=0;
// extern int disp_frame[50][144][176];
///////////////////////
BITMAPINFOHEADER bmi;
BITMAPINFO bm;
RGBQUAD rgbarray[256];
bmi.biSize = sizeof(BITMAPINFOHEADER);
bmi.biWidth = 176;
bmi.biHeight = 144;
bmi.biPlanes = 1;
bmi.biBitCount = 8;
bmi.biCompression = BI_RGB;
bmi.biSizeImage = 0;
bmi.biXPelsPerMeter = 0;
bmi.biYPelsPerMeter = 0;
bmi.biClrUsed = 0;
bmi.biClrImportant = 0;
bm.bmiHeader = bmi;
for (int color_index = 0; color_index < 256; color_index++)
{
rgbarray[color_index].rgbBlue = i;
rgbarray[color_index].rgbGreen = i;
rgbarray[color_index].rgbRed = i;
rgbarray[color_index].rgbReserved = 0;
}
bm.bmiColors[1] = rgbarray[0];
/////////////////////
CRect rcClient;
GetClientRect(rcClient); // See Note 1
rcClient.right=176;
rcClient.bottom=144;
CDC MemDC,*pDC;
CBitmap MemBitmap,*drawmem;
pDC = this->GetDC(); // Get Current DC
MemDC.CreateCompatibleDC(pDC);
CreateDIBSection(MemDC,bm,DIB_RGB_COLORS,disp_frame,NULL,0);
CBitmap *pOldBitmap =MemDC.SelectObject(&MemBitmap);
pDC->BitBlt(150,100,176,144,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(pOldBitmap);
ReleaseDC(pDC);
}
|
|
|
|
|
Have a look at CreateDIBSection documentation [^]. It states the 5th parameter (a pointer to a pointer) is an [out] one. It means you have to pass the address of a pointer and, on return, that pointer will contain the address of the allocated DIB section buffer, then you have to change the bit values of such buffer, according to disp_frame values, before selecting it into device context.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
rtant = 0;
bm.bmiHeader = bmi;
for (int color_index = 0; color_index < 256; color_index++)
{
rgbarray[color_index].rgbBlue = i;
rgbarray[color_index].rgbGreen = i;
rgbarray[color_index].rgbRed = i;
rgbarray[color_index].rgbReserved = 0;
}
bm.bmiColors[1] = rgbarray[0];
/////////////////////
CRect rcClient;
GetClientRect(rcClient); // See Note 1
rcClient.right=176;
rcClient.bottom=144;
CDC MemDC,*pDC;
CBitmap MemBitmap,*drawmem;
pDC = this->GetDC(); // Get Current DC
MemDC.CreateCompatibleDC(pDC);
CreateDIBSection(MemDC,bm,DIB_RGB_COLORS,disp_frame,NULL,0);
CBitmap *pOldBitmap =MemDC.SelectObject(&MemBitmap);
pDC->BitBlt(150,100,176,144,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(pOldBitmap);
ReleaseDC(pDC);
}
This was the piece of code which was posted previously. But the CreateDIBSection code
CreateDIBSection(MemDC,bm,DIB_RGB_COLORS,disp_frame,NULL,0); was having MemDC is a CDC type. But actually it should be HDC type. So I have rewritten the code as
HDC hDC;
hDC = CreateDC("DISPLAY",NULL,NULL,NULL);
HDC memDC = CreateCompatibleDC(hDC);
CreateDIBSection(hDC,bitmap,DIB_PAL_COLORS,ppbits,NULL,0);
HBITMAP memBM = CreateCompatibleBitmap(hDC,176,144);
SelectObject(memDC,memBM);
BitBlt(memDC,150,100,176,144,hDC,0,0,SRCCOPY);
But CreateDIBSection is creating exception. What could be the reason. Basically I could not get the difference between CDC and HDC. Could anyone give a clear solution to my problem. I am actually trying to display a grayscale image which exists as R=G=B values in memory.
|
|
|
|
|
Please surround code snippets with <pre> tags.
(1) What error message are you receiving?
(2) how did you define ppbits ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
The error message was Unhandled exception in decoder.exe(GDI32.dll): 0xc0000005 : Access Violation
the declaration for ppbits was void **ppbits.
Once this CreateDIBSection works i thought of filling ppbits with pixel values. That's why that particular piece of code is not available
|
|
|
|
|
jossion wrote: the declaration for ppbits was void **ppbits
The above is wrong.
You have to declare a pointer to void, for instance
void * pbits;
and then pass the address of the pointer (i.e. &pbits ) to CreateDIBSection :
CreateDIBSection(hDC,bitmap,DIB_PAL_COLORS, &pbits, NULL,0);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hello evry body, how is it possible to flash the icon of a certain frame window, in order to capture the attention of the user and see the asynchrounous event that happened and which relates to the frame whose icon is highlighted ?
Thank you in advance.
|
|
|
|
|
See FlashWindow()[^]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Thank you thank you very much !
|
|
|
|
|
You're welcome.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
I'd like to search the active window's client area for a given string and highlight it.
I've done this in VB using SelStart and SelLength.
I'm sure I've seen the same functionality available from a conventional Windows program, but can't remember what the win32 API calls are.
Does anyone know, or have tips on how to find out?
Thanks for the assist.
glyfyx
|
|
|
|
|
There is EM_SETSEL message though it works with edit boxes (or EM_EXSETSEL , with Rich Edit controls). AFAIK VB6 itself allows SelStart and SelLength only inside controls (i.e. they are TextBox methods).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Just a word of thanks - appreciated!
glyfyx
|
|
|
|
|
If this is a Win32 application without using MFC, create window as a child of the main window; use "edit" window class. You may want to subclass edit window but it is not necessary.
Use EM_* messages to tell edit window what to do. See MSDN for more information. EM_ messages are defined in WINUSER.H. Handle notification messages from control in a parent window, to see what control is doing. Notification code are also defined in WINUSER.H and are delivered as parameter of WM_COMMAND message.
For MFC application use CEdit class and call SetSel member function. Again, see MSDN for members reference. You can add notification handlers in a parent of edit control using Wizard.
JohnCz
MS C++ MVP
|
|
|
|
|
Thanks for taking time to provide such a complete answer - much appreciated!
glyfyx
|
|
|
|
|
You are very welcome. Glad to be of help.
JohnCz
MS C++ MVP
|
|
|
|
|
Hi
I want to insert the picture in the picture control in VC++ 6......
tell me how to do it
AbidBhat
|
|
|
|
|
Steps:
1) Add a .bmp image into resources,
2) Add a Picture Control onto the dialog template with the dialog editor,
3) Assign the resource ID of the image to the property of the Picture Control.
Maxwell Chen
|
|
|
|
|
|
If you want to insert bmp you can use of resource of program or for other foramts like jpg you can use of CImage class or GDI+.
|
|
|
|
|
Hamid. wrote: for other foramts like jpg you can use of CImage class or GDI+.
can u plz elaborate the procedure for doing this a little more....
thanx in advance ....
|
|
|
|
|
Not problem for read bmp files you can use of LoadImage and its simple to use for read other formats like jpg you can use like this
#incldue AtlImage.h
CImage m;
m.Load("c:\\1.jpg");
m.BitBlt(...);
and in the last use of m.Destro();
|
|
|
|
|
The simplest way is to create bitmap in the resource editor.
So-called picture control is nothing but a static control that has (among others) SS_BITMAP style.
Once you insert control and choose appropriate style, choose Bitmap type in a property box and assign ID of the bitmap image you want to display using the same property box.
That is all you need to do unless you want to customize display and control how images are displayed.
JohnCz
MS C++ MVP
|
|
|
|
|
dear all
for (int iiY=0;iiY<width;iiy++)>
{
for (int iiX=0;iiY<height;iix++)>
{
for (int kk=0;kk<3;kk++)
{
ucImgdata[iiY]=ucImagdata[iiY-1]*mask[kk];
}
}
}
my problem is how to get the following loop:
ucImgdata = ucImgdata[iiY-1]*mask[0]+ucImgdata[iiY]*mask[1]+ucImgdata[iiY+1]*mask[2];
Li Zhiyuan
|
|
|
|
|
First - Your for loops are incomplete.
You can achive the same using the following loop -
int testval = 0;
for (int i = -1, int j = 0; i < 3; i++, j++)
{
testval += ucImagedata[iiY + i]*mask[j];
}
|
|
|
|