Avatar of thready
thready
 asked on

Copy Bitmap to CDC without StretchDIBits?

Hi,

How can I copy a bitmap to a CDC without using StretchDIBits?

Thanks,
Mike
Editors IDEsMicrosoft DevelopmentSystem Programming

Avatar of undefined
Last Comment
thready

8/22/2022 - Mon
AndyAinscow

Use BitBlt instead.
thready

ASKER
Hi Andy!  I don't see how to use BitBlt - there are not HBITMAP parameters....
AndyAinscow


Attaches hBitmap to a CImage object.      
  void Attach(
   HBITMAP hBitmap,
   DIBOrientation eOrientation = DIBOR_DEFAULT
) throw();



and you can use the BitBlt of the CImage to copy to a destination CDC

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
thready

ASKER
I tried the following -- when it's about to be finished the BitBlt, in the Win32 code, it is about to release the DC and I get an assertion - the hBitmap is not equal to the m_hBitmap as it should be.

Does the code below look right?
	CImage i;
	i.Attach(m_hDib);
	i.BitBlt(m_pDC->m_hDC, 1440,-1440);

Open in new window

AndyAinscow

I don't see why that code should give you the error you report (ie the code looks OK).


ps. Where do you get the bitmap?  CImage can load directly from files for example.
thready

ASKER
I get the bitmap from the following line:

HDC      hMemDC = ::CreateCompatibleDC(NULL);
HBITMAP hDib = ::CreateDIBSection(hMemDC, &bmi, DIB_RGB_COLORS, &pBitmapBits, NULL, (DWORD)0);

I then draw to the bitmap with OpenGL - this works fine because I get the output no problemo if I use StretchDIBits - but since I'm drawing my bitmap at exactly the same size that I'm later outputting on my printer DC, I don't want any modification of my image (and it is being modified).....  
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
AndyAinscow

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
thready

ASKER
One is a printer DC - the other is a memory DC.  The memDC is associated with my OpenGL rendering context.  I'm not sure if they have different mode settings - but it looks to me like you're right.  In any case, I've decided to go about this in a different way - I am printing through latex instead of with the device context directly.

Thanks,
Mike