|
I got the following problem: I got a DC in which I need to put an image comprised of more bitmaps. However, if I paint the bitmaps one by one, I get some flicker.
So I need 1 memory DC to paint the bitmaps with. 1 memory DC to paint them in. And then this last memory DC will get bitblt-ed on the third and real DC.
But the problem is that when I can't paint from the first DC to the second. I select the bitmaps in the first DC and bitblt them in the second. But when I do my stuff and bitblt the second DC upon the third, I get only white. Anybody got any clue what I'm messing up here?
I didn't include code 'cause my routine is rather complicated and it's not written in C++ but here is something that may be of use:
1. I create both memory DCs using "CreateCompatibleDC(REALDC)".
2. I select bitmaps in the first DC using "SelectObject (hdcMemory, myBITMAP)".
3. I simply bitblt from first DC to second DC at the desired coordinates.
4. I repeat steps 2. and 3. for 4 images, bitblt-ed at various coordinates within the second DC.
5. Now I bitblt the second DC in the real DC, the third one, the visual source.
All is white................
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
can u BitBlt() first memory DC to real DC properly?
default size of memory DC is 1x1 pixels.
did u set suitable size for all other memory DCs?
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
|
|
|
|
|
I can't paint directly to the real DC 'cause I need to put more images. So I need an intermediate DC in which to dump the pictures piece by piece and then bitblt in the original DC.
I set the size of the memory DC by selecting a bitmap of the desired size in it. Is that correct.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
|
I don't know what you're trying to suggest here and I don't think I'm gonna like the sound of it. But please, give it a shot ::- ).
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Not a direct reply, but you should look at Image Viewer Utility[^] by PJ Arends. It should help you a lot while debugging the problem.
My guess is that you have incompatible bitmaps selected into your DCs.
|
|
|
|
|
Hi
I'm drawing a bitmap in the client area. However, after restoring from being minimized the client area is not repainted (non client area is shown). My guess is that WM_PAINT is not send, but why? I thought after WM_SIZE (which is received) WM_PAINT is send automatically. I even tried to force the repainting in WM_SIZE but that doesnt work either (or maybe i forced it the wrong way...). Please help
here's some code:
Creating the Window:
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = ::GetModuleHandle(NULL);
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE (ID_ICON_SLICE_32));
wc.hIconSm = (HICON)LoadImage (GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ICON_SLICE_16), IMAGE_ICON, 16, 16, 0);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
g_hWnd = CreateWindowEx(
0,
g_szClassName,
"SliceEdit v0.1",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, g_Width, g_Height,
NULL, NULL, GetModuleHandle(NULL), NULL);
// in winproc DefWindowProc deals with WM_SIZE
...
case WM_PAINT:
PAINTSTRUCT PS;
HDC hDc = BeginPaint(m_hWnd,&PS);
SetDIBitsToDevice (hDc, 0, 0, w, h, 0, 0, 0, h, m_pBits, &m_BMI, DIB_RGB_COLORS);
EndPaint(m_hWnd,&PS);
-- modified at 15:39 Saturday 8th April, 2006
|
|
|
|
|
|
thanks, but didn't work
|
|
|
|
|
did u see ur bitmap at least for once?
if yes, is the line correct:
wc.hInstance = ::GetModuleHandle(NULL);
?
why do not use
wc.hInstance = hInstance;//which is one of params of proc
?
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
|
|
|
|
|
hi again
yes, the bitmap is drawn. the prob is, when i first minimize the window and then bring it back to the screen (via clicking on it in the taskbar) the client area (the bitmap) is not redrawn, the area is white. Its only drawn again when i move the mouse over the window or when I move another window in front of it (so i guess when WM_PAINT is called).
I used GetModuleHandle(NULL) because actually the window creation is in another method (which is called from winmain). But still, I tried your suggestion and it doesnt solve my problem. Any other tips? Thanks a lot
|
|
|
|
|
last tip, I have no more.
if it is called from WinMain(), why do not pass hInstance from WinMain() to the function which contains ur code above?
such as:
MyCreateFunction(HINSTANCE hInstance);
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
|
|
|
|
|
yes thanks, i did that but it doesnt solve the problem
|
|
|
|
|
Hi naal11,
Whats m_pBits, &m_BMI? Can you be more specific
But if you use WM_PAINT for show bitmap I think It's not problem
I run and then Min and Max window but bitmap is fix.of course I use
BitBlt.
-----------------------------------------
please try
InvalidateRect(hWnd,&rect,1);
|
|
|
|
|
m_pBits it a pointer to the pixeldata. m_BMI is the BITMAPINFO -struct. But these things shouldnt be the prob since drawing the bitmap works. I tried InvalidateRect(hWnd,NULL,1) but its still not working. I even tried painting into the device context (SetDIBitsToDevice...) inside the WM_SIZE case but no effect. thanks for your help
|
|
|
|
|
naal11
please try
RECT rect;
GetWindowRect(hWnd,&rect);
InvalidateRect(hWnd,&rect,1);
InvalidateRect(hWnd,NULL,1)
|
|
|
|
|
msdn docs say that by passing NULL the entire client area is invalidated. but i tried it your way and it doesnt work
thanks anyway
|
|
|
|
|
naal11 wrote: SetDIBitsToDevice (hDc, 0, 0, w, h, 0, 0, 0, h, m_pBits, &m_BMI, DIB_RGB_COLORS);
should it not be SetDIBitsToDevice (hDc, 0, 0, w, h, 0, 0, w, h, m_pBits, &m_BMI, DIB_RGB_COLORS);
Also try calling InvalidateRect from your WM_SIZE handler.
|
|
|
|
|
Well its 0 cause 0 is the first scanline. Probally if that wasnt correct i wouldnt see the bitmap at all, but it works. Its just that repainting problem after i restore the window.
I tried InvalidateRect(hWnd,NULL,1) but its still not working. I even tried painting into the device context (SetDIBitsToDevice...) inside the WM_SIZE case but no effect. thanks for your help
|
|
|
|
|
1/ Are you overriding WM_ERASEBKGND?
2/ Do you redraw, if you do something boring like:
TextOut (ps.hDC, 0,0, "Hello", 5); (probably not the
right order for the params...
That should narrow the problem to a missing WM_PAINT message,
or bad bitmap drawing...
Iain.
|
|
|
|
|
1) im not catching wm_earasebkgnd
2) no i only redraw the bitmap in wm_paint
best regards micimausi
|
|
|
|
|
Maybe I located the prob by myself now. Could it be this message loop? When i outcomment "Waitmessage()" the desired repainting occurs. Could someone explain me whahts going on with this Waitmessage call?
Thanks
while(true)
{
if(PeekMessage(&Msg, NULL, 0, 0,PM_REMOVE))
{
if(Msg.message == WM_QUIT)
{
break;
}
else
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
WaitMessage();
}
|
|
|
|
|
I want to transfer bitmap over socket. For that I need pixel buffer retrieved from bitmap and I use GetDIBits. When I debug, I get the nLength value equivalent to the height of bitmap. but all the values of lpvBits array are 0.
What I am doing wrong. Any help
LPBYTE lpvBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbmi->bmiHeader.biSizeImage);
int nLength = GetDIBits(hdc,hCaptureBitmap,0,(WORD)pbmi->bmiHeader.biHeight,lpvBits,pbmi,DIB_RGB_COLORS);
Also can someone please tel me is it the correct method for transfering a bitmap
over socket. or theres a better/correct method.
Thanx alot
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg."
- Bjarne Stroustrup
|
|
|
|
|
i think it is easier to open bitmap file directly if allowed.
u should zip the file - file size of bitmap is to large too be transfered by socket.
and, how does receiver decode info if without BITMAPINFOHEADER?
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
-- modified at 13:02 Saturday 8th April, 2006
|
|
|
|
|
Identity Undisclosed wrote: Also can someone please tel me is it the correct method for transfering a bitmap
over socket. or theres a better/correct method.
depends on the size of the image. You can send a single image as a raw packet, but you have to remember not to exceed the maximum packet size for your socket library. Any socket based packet is divided into MTU (usually 1500) byte sized packets and delivered one at a time. In UDP if all packets are received then the receiver gets the full sized packet, if any one is missing the packet is ignored (UDP is non-guarenteed delivery), TCP will exchange and verify every piece one at a time, when all are verified the packet is delivered (or connection times out if it takes too long).
There is no "correct way" there is only each programmer's preferred way, which is often application based. If you are sending video frames, you may not care about reliable transmission, just wait for the next frame.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|