Link to home
Start Free TrialLog in
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
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Use BitBlt instead.
Avatar of thready
thready

ASKER

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

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

Avatar of 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

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.
Avatar of 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).....  
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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