|
I tried this way, but it displays just a white page... here is how I did it
working version
CClientDC dc(this);<br />
dib->Draw(&dc,x,y);
where dib->Draw function is defined as below-
void DIBSection::Draw(CDC* pdcDest, int xs, int ys) <br />
{<br />
pdcDest->BitBlt( 0, 0, m_size.cx, m_size.cy, m_pdc, xs, ys, SRCCOPY);<br />
}
modified version
CDC* m_pdc = new CDC ;<br />
m_pdc->CreateCompatibleDC(NULL);<br />
dib->Draw(m_pdc, 0, 0, w*zoom_const, h*zoom_const, 0, 0, w, h);<br />
CClientDC dc(this);<br />
dc.SelectObject(m_pdc);<br />
dc.BitBlt(0, 0, w*zoom_const, h*zoom_const, m_pdc, 0, 0, SRCCOPY);
where w, h are width and height of my image and zoom const is the scaling factor. dib is an object of my DIBSection class. dib->Draw does nothing more except it calls the dc->BitBlt function with its own defined dc in the Blt function, which is created when the dib object is created with bitmap data.
am I doing something wrong here??
-PNT
PKNT
|
|
|
|
|
Kiran Satish wrote: dc.SelectObject(m_pdc);
you can't select a DC into another DC.
you need to create a compatibleDC, create a compatibleBitmap (of the scaled size), select that btimap into that DC, then BitBlt from your source DC onto the scaled DC/bitmap. then you can use that scaled bitmap to draw
|
|
|
|
|
Thanks for the reply, I tried as you suggested...
<br />
CClientDC dc(this);<br />
CDC tempDC;<br />
tempDC.CreateCompatibleDC(NULL);<br />
CBitmap tempBMP;<br />
tempBMP.CreateCompatibleBitmap(&tempDC, w*zoom_const,h*zoom_const);<br />
tempDC.SelectObject(tempBMP);<br />
dib->Draw(&tempDC, 0,0,w*zoom_const,h*zoom_const,0,0,w,h); <br />
dc.BitBlt( 0, 0, w*zoom_const,h*zoom_const, &tempDC, sp.x, sp.y, SRCCOPY);
it still shows me a black image.... am I still doing wrong??, sorry I am not soo familiar with CBitmaps and DCs. Just learning now
-PNT
PKNT
|
|
|
|
|
Kiran Satish wrote: dib->Draw(&tempDC
what is Draw expecting as its first parameter (CDC, HDC, CDC*) ?
as a test, you might try something simple like drawing a rectangle (CDC::FillSolidRect) on that tempBMP, just to see if maybe the problem is in the Draw function.
also tempDC.SelectObject(tempBMP); should probably be tempDC.SelectObject(&tempBMP);
|
|
|
|
|
That draw function is same before...
<br />
void DIBSection::Draw(CDC* pdcDest, int x, int y, int nw, int nh, int xs, int ys, int w, int h)<br />
{<br />
pdcDest->StretchBlt( x, y, nw, nh, m_pdc, xs, ys, w, h, SRCCOPY);<br />
}
where m_pdc is the DC of dib where the actual pixel data is stored.
will try the simple fillrect function.
-PNT
PKNT
|
|
|
|
|
I tried to fill the DC with RED color and it still shows up as 300x300 black image ...
tempDC.SelectObject(&tempBMP);<br />
tempDC.FillSolidRect(0,0,300,300,RGB(255,0,0));<br />
dc.BitBlt( 0, 0, 300,300, &tempDC, 300, 300, SRCCOPY);
-PNT
PKNT
|
|
|
|
|
when you call CreateCompatibleBitmap, try giving it the DC you're going to BitBlt it to, not the temp DC.
|
|
|
|
|
Yeh.. tht made it work... but if you dont mind, could you tell me why it is like tht??
thanks,
-PNT
PKNT
|
|
|
|
|
the Bitmap needs to be compatible with the DC you're BitBlt'ing to. when you use the memory DC for the C*C*Bitmap call, the bitmap created will be monochrome. if you use an output DC, it will match the settings of that DC.
or, as Microsoft puts it:
Because memory device contexts allow both color and monochrome bitmaps, the format of the bitmap returned by the CreateCompatibleBitmap function differs when the specified device context is a memory device context. However, a compatible bitmap that was created for a nonmemory device context always possesses the same color format and uses the same color palette as the specified device context.
Note: When a memory device context is created, it initially has a 1-by-1 monochrome bitmap selected into it. If this memory device context is used in CreateCompatibleBitmap, the bitmap that is created is a monochrome bitmap. To create a color bitmap, use the hDC that was used to create the memory device context, as shown in the following code...
|
|
|
|
|
It working definitely better than before, but what I am trying to do now is, rather than doing this work everytime I update/refresh the window, is there any way I can reduce this work, but doing this only once for each zoom constant? For now, this is how it goes..
CClientDC dc(this);<br />
CDC tempDC;<br />
tempDC.CreateCompatibleDC(NULL);<br />
CBitmap tempBMP;<br />
tempBMP.CreateCompatibleBitmap(&dc, w*zoom_const,h*zoom_const);<br />
tempDC.SelectObject(&tempBMP); <br />
dib->Draw(&tempDC, 0,0,w*zoom_const,h*zoom_const,0,0,w,h); <br />
dc.BitBlt( 0, 0, w*zoom_const,h*zoom_const, &tempDC, sp.x, sp.y, SRCCOPY);
where sp is the scroll position. But lets say I scrolled the image, in this case the zoom constant is still the same, I just need to update the position of the image wrt view window. I see stretching the bitmap all the time is very time consuming .
thanks,
-PNT
PKNT
|
|
|
|
|
create a CBitmap object member of your window class. every time your zoom level changes:
1. delete the contents of that CBitmap
2. create a new (compatible) bitmap of the appropriate size
3. do your StretchBlt onto that
the code to do that is basically the same as what you have above, but you drawing into m_zoomedBitmap (or whatever) instead of tempBMP, and you use StretchBlt there.
then, when it's time to do the OnPaint/OnDraw, draw that member CBitmap with a normal BitBlt.
|
|
|
|
|
I tried exactly what you said (I hope), declared a CBitmap member in Document class and using it instead of tempBMP like below..
CClientDC dc(this);<br />
if (zoom_const >1)<br />
{<br />
CDC tempDC;<br />
tempDC.CreateCompatibleDC(NULL);<br />
if (m_bZoomUpdate)
{<br />
GetDocument()->m_zoomedBMP.CreateCompatibleBitmap(&dc, w*zoom_const,h*zoom_const);<br />
tempDC.SelectObject(&GetDocument()->m_zoomedBMP);<br />
dib->Draw(&tempDC, 0,0,w*GetDocument()->zoom_const,h*GetDocument()->zoom_const,0,0,w,h); <br />
m_bZoomUpdate = false;<br />
}<br />
else<br />
tempDC.SelectObject(&GetDocument()->m_zoomedBMP);<br />
dc.BitBlt( 0, 0, w*zoom_const,h*zoom_const, &tempDC, sp.x, sp.y, SRCCOPY);<br />
}<br />
else
dib->Draw(&dc, 0,0,w*zoom_const,h*zoom_const,sp.x,sp.y,w,h);
It works... and the drawing is as normal with no delays... Now time for getting the exact location of a pixel in zoom mode .
thanks,
-PNT.
PKNT
|
|
|
|
|
It's working fine on both small and large image files. But the only problem that I found is the stretching doesnt work after reaching certain zoom level. I tried 3 different sizes of images,
one is 1000x1000 and it works fine for the whole zoom range that I have (1x - 5x)
second image is 3616x3581 and it works fine untill 2.1x and shows only a white image after that (at 2.2x its dimensions are 7593x7520)
and the third image is 5540x3615 and it works only untill 1.7x and from then shows only white image (at 1.8x its dimensions are 9972x6507).
Is there any limit on the max size of a compatible bitmap that you can create??
thanks,
-PNT.
PKNT
|
|
|
|
|
Kiran Satish wrote: Is there any limit on the max size of a compatible bitmap that you can create??
yes, definitely.
it varies from system to system, though.
|
|
|
|
|
I am back with a problem closely related to this topic... everything is fine and was able to magnify the images upto the point when I load images of 40MB in size. Then this function behaves differently on different machines (same OS) except on one machine with 64bit OS (where it can magnify to any scale without problem). On some machines it doesn't even magnify one step and on some machines it magnifies to few steps (after that it just shows either white or black frame when you try to magnify). Here is the code that I am currently using-
if (GetDocument()->zoom_const >100)
{
CDC tempDC;
tempDC.CreateCompatibleDC(NULL);
if (GetDocument()->m_bZoomUpdate)
{
GetDocument()->m_zoomedBMP.DeleteObject();
GetDocument()->m_zoomedBMP.CreateCompatibleBitmap(&dc, w*GetDocument()->zoom_const/100,h*GetDocument()->zoom_const/100);
tempDC.SelectObject(&GetDocument()->m_zoomedBMP);
dib->Draw(&tempDC, 0,0,w*GetDocument()->zoom_const/100,h*GetDocument()->zoom_const/100,0,0,w,h);
GetDocument()->m_bZoomUpdate = false;
}
else
tempDC.SelectObject(&GetDocument()->m_zoomedBMP);
dc.BitBlt( 0, 0, w*GetDocument()->zoom_const/100,h*GetDocument()->zoom_const/100, &tempDC, sp.x, sp.y, SRCCOPY);
}
else
dib->Draw(&dc, 0,0,w*GetDocument()->zoom_const/100,h*GetDocument()->zoom_const/100,sp.x,sp.y,w,h);
Is there any other way to do this more efficiently and overcome this problem.
thanks,
PKNT
|
|
|
|
|
you'll probably need to start cropping the input image down to the part that you're going to draw, instead of trying to resize the whole thing.
|
|
|
|
|
I am thinking of this, but dont know how to do, could you please link me to some tutorials on how to do this??
thanks,
PKNT
|
|
|
|
|
sorry, i don't know of any tutorials.
|
|
|
|
|
Hello,
i have two dialogs in my project, the first one is main dialog, and the second one is helper dialog, and there is a button on main dialog, if i click the second dialog must appear under the main dialog, but i dont know how to do it,
anyone could help me please?
thanks
|
|
|
|
|
I don't even want to think about how to do that, it's just a bad idea. Try thinking of a better solution, see if that helps.
|
|
|
|
|
led mike wrote: it's just a bad idea
Why?
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.
|
|
|
|
|
Under or Below ?
For me :
Under relates to Z-Order.
Below relates to Y position.
|
|
|
|
|
it is below, not under, sorry for that
|
|
|
|
|
Get the window rect (GetWindowRect ) of your main dialog.
Get the window rect (GetWindowRect ) of your child dialog.
Do a bit of computation on those values, taking into account the border and title bar sizes and you MoveWindow or SetWindowPos to move the child window below the main dialog.
|
|
|
|
|
How do we get dialogs coordinates?
|
|
|
|
|