I have a MFC application with toolbars (using CMFCToolbar). I create the toolbar bitmap on the fly using bitmaps from files and resources. The DIBs have different color formats.
- So I create an empty bitmap toolbar image compatible to screen DC.
- Then I open all the bitmaps and blit the content to the toolbar bitmap (GDI does colorspace conversion and stretching for me).
- Then I save the bitmap to a 24-bit DIB file.
- Then I create the toolbar object and load the image.
That has worked for ages and is working now except for one case:
Recently we had to enable GDI scaling for Windows 10 1703 and later. On a system with high resolution display and 200% scaling (like Surface) the following effect occurs:
All toolbar icons are distorted.
I also found the reason:
When saving the composed image I only get the top-left quarter of the image. Width and height of the bitmap did not change (say 1024x15) compared to normal resolution display without GDI scaling. But that bitmap only contains the pixels of the top-left quarter (see example below).
So I assume the device context tells Windows about 200% scaling. When blitting from source to target the image gets scaled up automatically but the dimension of the bitmap does not change.
How can I save the unscaled bitmap?
-or-
How can I correctly save the scaled bitmap? Where to get the missing pixels? Where to get proper dimensions? (HBITMAP refers only to unscaled dimensions).
Example:
no GDI scaling, correct:
200% scaling, same dimensions, but only top-left quarter of the correct image: