|
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?
|
|
|
|
|
check out GetWindowRect
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.
|
|
|
|
|
A combination of these APIs should do everything you need:
GetDeviceCaps() - get screen dimensions
ShowWindow() - show and hide windows
GetWindowRect() - get dimensions of windows
MapWindowPoints() - convert window points/dimensions relative to other windows
MoveWindow() - Move/resize windows
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: A combination of these APIs should do everything you need:
Yes it will... well exclusive of providing the user with a decent experience. But yeah, that's not something he needs right?
|
|
|
|
|
led mike wrote: well exclusive of providing the user with a decent experience
Do you really think that's an issue here?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Didn't I warn you cut back on those Filet-O-Fishies?
|
|
|
|
|
Hello,
I have an IDispatch pointer with which I am reading an excel file.
I know how to find out how many rows are used in the sheet but how do I find out how many columns ae used.
Is there any help available to find the details of the methods used in the Application,Workbook etc classes.
Prithaa
|
|
|
|
|
//PIXEL INFORMARTION
unsigned char * t=AreaBIR.GetItemData();
m_winImage.SetPixelsFromData(200, 152, t, false);
m_winImage.IntervalEqualize(0,240,0,255,0,255);
::InvalidateRect(NULL,NULL,FALSE);//Show image on screen
BITMAPINFOHEADER BMIH;
BMIH.biSize = 40;
BMIH.biBitCount = 8;
BMIH.biPlanes = 1;
BMIH.biCompression = 0;
BMIH.biWidth = 152;
BMIH.biHeight = 200;
BMIH.biSizeImage = 30400;
HDC pDC = ::GetDC(0);
HBITMAP hbitmap = CreateDIBSection(pDC->GetSafeHdc(), (CONST BITMAPINFO*)&BMIH, DIB_RGB_COLORS,
(void**)t, NULL, 0);
//Here write the bitmap to a .bmp file (This function works fine)
WriteBMPFile(hbitmap, "C:\\temp.bmp",pDC);
}
The variable "t" contains the pixels information of a fingerprint. I use "t" to display a fingerprint image in a window and works fine, however when I use "t" to create a HBITMAP object, and I pass the HBITMAP object to the WriteBMPFile function, a BLACK image is generated. I believe that my problem is in the creation of the HBITMAP object. Any help will be aprreciated
BTW I found the implementation of WriteBMPFile in http://www.saturnsoftmills.com/Articles/A6.pdf
Thanks
Miguel
|
|
|
|
|