Re: Drawing correctly a Bitmap
 
"Nord Pierre" <Well ...> wrote in message 
news:499c0c79$0$4748$426a34cc@news.free.fr...
Hello,
Here is my problem :
I have an image in memory (the color depth can be 8/16/24/32bits) and i 
need to display it correctly on screen but the color depth can be anything 
different (8,15,16,24,32 ...) So i've tried :
// myBmp is the bitmap to display (no need to be a CBitmap ?)
CPaintDC dc(winHandle);
CDC dcMemory;
BITMAP bmpInfo;
CBitmap *pOldBitmap;
if (dcMemory.CreateCompatibleDC(&dc))
{
 pOldBitmap = dc.SelectObject(&myBmp);
 dcMemory.SelectObject(&myBmp);
 dc.BitBlt(pX,pY,imWidth,imHeight,&dcMemory,0,0,SRCCOPY);
 dc.SelectObject(pOldBitmap);
}
It works only if the display has the same depth color as the bitmap of 
course. So i need to convert the bitmap before doing anything else.
My question is : Is there any fonction/class to avoid doing this 
conversion myself. Well, an automatic converter exist or i must write it ? 
Or did i miss something important here ?
Don't select myBmp into dc.  Only select it into the dcMemory (myBmp is the 
source bitmap, and has nothing to do with the destination).  Try rewriting 
your code:
 if (dcMemory.CreateCompatibleDC(&dc))
 {
  pOldBitmap = dcMemory.SelectObject(&myBmp);
  dc.BitBlt(pX,pY,imWidth,imHeight,&dcMemory,0,0,SRCCOPY);
  dc.SelectObject(pOldBitmap);
 }
If this still doesn't work, is the destination (screen) set to 8 bit (256 
colors)?  This uses palettes.  You have to write all manner of code to set 
the desired palette onto the destination DC and map colors from the image 
accordingly.  But 8 bit is not used in modern Windows anymore, so I don't 
think this is the problem.
-- David