Getting a bmp copy of what i printed

This is a discussion on Getting a bmp copy of what i printed within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I'm printing some information to a printer DC, and would like to print a copy of this info to ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Getting a bmp copy of what i printed

    Hi.
    I'm printing some information to a printer DC, and would like to print a copy of this info to a bmp file. What function would i use?
    I thought CreateDIBSection() didi this, but it only creates an empty bitmap in the DC...
    Will i have to print all the info to the DC as pixels on the bitmap?

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    This doesn't make sense to me. If you already have the DC and you are using the printer DC to print the bitmap, then you already have the bitmap. Saving it is as simple as using GetBitmapBits() and writing the BMP header and then the buffer that function filled to disk. And if you don't want to do all that I'm fairly sure GDI+ will write a BMP file to disk for you provided you send it the appropriate information to do so.


    CDC::GetBitmapBits() is the MFC function - I'm not sure what the actual Win32 function is.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    GetDIBits. However, many printer drivers are unlikely to support it. I think the best way is to just to output identical content to a memory DC and the printer DC. You could create a function that outputs your print content to a given DC, and then call it with each DC.
    Last edited by anonytmouse; 04-13-2007 at 03:06 AM.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Ok, so the easiest solution is to output the data to a memory dc, and capture tha bitmap from there..
    The problem, however, is that i can't capture a bitmap of the DC.. i only get dummy data in the bits..

    Code:
    BITMAPINFO info;
    	TIFF *tif;
    	UINT32 w = GetDeviceCaps(dc, HORZRES);
    	UINT32 h = GetDeviceCaps(dc, VERTRES);
    	BYTE *bits = (BYTE*)malloc(w * h);
    	HBITMAP hBmp;
    	BITMAP bitty;
    
    	HDC mDC = CreateCompatibleDC(dc);
    	hBmp = CreateCompatibleBitmap(mDC, w, h);
    	SelectObject(mDC, hBmp);
    	BitBlt(mDC, 0, 0, w, h, dc, 0, 0, SRCCOPY);
    	GetObject(hBmp, sizeof(BITMAP), &bitty);
    	
    	BITMAPINFOHEADER header;
    	header.biSize = sizeof(BITMAPINFOHEADER); 
    	header.biWidth = w; 
    	header.biHeight = h; 
    	header.biPlanes = bitty.bmPlanes; 
    	header.biBitCount = 1; 
    	header.biCompression = BI_RGB;
    	header.biSizeImage = 0; 
    	header.biClrUsed = 0; 
    	header.biClrImportant = 0; 
    	info.bmiHeader = header;
    	info.bmiColors->rgbRed = NULL;
    	info.bmiColors->rgbGreen = NULL;
    	info.bmiColors->rgbBlue = NULL;
    	info.bmiColors->rgbReserved = NULL;
    	
    	GetDIBits(mDC, hBmp, 0, h, &bits, &info, DIB_RGB_COLORS);
    After GetDIBits() all bits in the "bits" array are set to 205...
    if i create a new window dc, do i have to do all the drawing again, or could i copy the original dc to the new one??

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    IF dc is a printer DC it is unlikely you will be able to copy from it. It is best to think of a printer DC as one-way, you can put stuff into it but not copy stuff out.

    Also, the GetDIBits call has a couple of problems.

    First, get rid of the highlighted ampersand:
    Code:
    	GetDIBits(mDC, hBmp, 0, h, &bits, &info, DIB_RGB_COLORS);
    Second, hBmp must not be selected into a DC when GetDIBits is called.

    Do you really want a monochrome bitmap?

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Yes, the bits variable is a pointer to an array.. I replaced the createdibsection function, thereby the **...
    (didn't see the error...)
    The bitmap is going to be used to create a tiff copy of a black & white report, so it doesn't need colors..
    Seems i have to reprint the report to a new DC then..

    Thank you for the assistance, you have been very helpful

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Now i'm about to give up..
    I have now created a window width as the printer dc.
    I then getdc() from this window(w=4960, h=7016), but this dc is restricted to 1024x768, hence the getdc() function only fetches the visible area of tne window.. Is it possible to fetch the entire window area into a dc, not only the visoble?
    Another problem is that the bitmap i think i fetcth from the dc with GetDibBits(), only displays as black and white vertical stripes, while the window displays the correct data..

    Suggestions?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading BMP
    By Mortissus in forum C Programming
    Replies: 4
    Last Post: 02-02-2006, 05:32 AM
  2. dynamic memory alloccation & returning objects
    By haditya in forum C++ Programming
    Replies: 8
    Last Post: 04-21-2005, 11:55 PM
  3. Strange problem with bmp
    By Victor in forum Linux Programming
    Replies: 2
    Last Post: 04-04-2005, 02:48 PM
  4. Copy a text in BMP file
    By gardenair in forum Tech Board
    Replies: 6
    Last Post: 10-06-2003, 07:15 AM
  5. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 10:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21