CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 1999
    Posts
    67

    Print and printpreview

    Hi, I know this topic has been up several times, and I have searched different thread for several days without any sucess of solving my problem.

    I have no problem with printing text, lines etc, but when it comes to a bitmap things get complicated for my small brain.

    The bitmap shows in the preview but I only get empty papers from the printer. Anyone know what I do wrong?


    this is how my OnPrint looks like.

    void CPrinttest1View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
    {
    pDC->SetMapMode(MM_TWIPS);

    CBitmap bmp;
    bmp.LoadBitmap(IDB_BITMAP1);

    CRect rectDraw(40,40,250,250);

    CDC memDc;

    memDc.CreateCompatibleDC(pDC);

    CBitmap *pOldBmp = memDc.SelectObject(&bmp);
    BITMAP bm;
    bmp.GetBitmap(&bm);

    CSize pBmpSize;

    //A 'normal' copy, but it still needs a stretch because of the map mode
    long nWidth = this->PointsToTwips(bm.bmWidth);
    long nHeight = -this->PointsToTwips(bm.bmHeight);
    POINT pos = this->PointsToTwips(rectDraw.left, rectDraw.top);
    pDC->StretchBlt(pos.x, pos.y, nWidth, nHeight, &memDc, 0, 0,
    bm.bmWidth, bm.bmHeight, SRCCOPY);

    pBmpSize.cx = bm.bmWidth;
    pBmpSize.cy = bm.bmHeight;


    memDc.SelectObject(pOldBmp);

    }

    All help will be appretiated

    thx
    Anders Jansson

  2. #2
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939
    The problem is due to the printer DC not supporting the StretchBlt or BitBlt calls. It works OK in print preview because the preview DC is a screen DC which supports these calls.

    If you want to print a bitmap, convert it to a DIB and use StretchDIBBits() to plot it. This should work for both screen/printer DC's.
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  3. #3
    Join Date
    Sep 1999
    Posts
    67
    ah, thx, any chance u have the code needed for the conversion?


    thx alot

    Anders

  4. #4
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939
    You should be able to find in the Bitmap section here or at CodeProject.
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  5. #5
    Join Date
    Sep 1999
    Posts
    67
    Thx

    /Anders

  6. #6
    Join Date
    Sep 1999
    Posts
    67
    darn, I cant found much help on DIBs, anyone know how to convert to a DIB so I can use the StretchDIBlt function?

    All help really appretiated, best would be if anyone have a few lines of code


    /Anders

  7. #7
    Join Date
    Sep 1999
    Posts
    67
    Ok, seems like I got most of it working now, so if anyone needs any help let me know and I'll try to help out.

    Only problem I still have is printing very large images, it work for 7mbyte images but not for 15mbytes images, might be a printer problem though. Anyone know anything about that? Only getting blank papers.


    /Anders

  8. #8
    Join Date
    Mar 2001
    Location
    Colorado
    Posts
    241
    hello - I am having this same problem with printing bitmaps, and would really appreciate any sample code or links to sample code for getting this to work.

    Thanks in advance,


    Wade

  9. #9
    Join Date
    Sep 1999
    Posts
    67

    Cool

    I sent you some sample code hope it helps.

    /Anders

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured