Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Printing a screen image (StretchBlt error)

Printing a screen image (StretchBlt error)

Scheduled Pinned Locked Moved C / C++ / MFC
helpdesign
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wim Engberts
    wrote on last edited by
    #1

    I am writing a graphic design tool. I am using a device context to produce the image on screen. Now I want to be able to print the image to the printer. What I am doing so far is: Create the screen device context : CDC *m_pDC = CreateDC (); Do all kinds of weird and wonderful things to produce the image (all of this works, since I do get the image I want on screen) When the user presses the Print option from the menu, I use the CPrintDialog class to select the printer, and subsequently I get a HDC by “CPrintDialog Print.CreatePrinterDC ();” Then I calculate the size on paper by the following piece of code: POINT point; POINT start; point.x = GetDeviceCaps (hDC, PHYSICALWIDTH); start.x = GetDeviceCaps (hDC, PHYSICALOFFSETX); point.x -= (start.x*2); point.y = GetDeviceCaps (hDC, PHYSICALHEIGHT); start.y = GetDeviceCaps (hDC, PHYSICALOFFSETY); point.y -= (start.y*2); DPtoLP (hDC, &point, 1); DPtoLP (hDC, &start, 1); I already have a POINT named “Source”, that holds the size of the screen DC. Then I call: if (!StretchBlt (hDC, start.x, start.y, point.x, point.y, m_pDC->GetSafeHwnd (), 0, 0, Source.x, Source.y, SRCCOPY)) And this is where all goes wrong! This fails, and the error message (as obtained by FormatMessage and GetLastError) says: “The parameter is incorrect” As far as I can see, the size on paper is correct, since I also write a (test) rectangle with these positions: Rectangle (hDC, start.x, start.y, point.x, point.y); and this produces a rectangle on paper with the size and position as I would expect. Can anyone help me out here. William -- modified at 7:29 Thursday 17th August, 2006

    S C P 3 Replies Last reply
    0
    • W Wim Engberts

      I am writing a graphic design tool. I am using a device context to produce the image on screen. Now I want to be able to print the image to the printer. What I am doing so far is: Create the screen device context : CDC *m_pDC = CreateDC (); Do all kinds of weird and wonderful things to produce the image (all of this works, since I do get the image I want on screen) When the user presses the Print option from the menu, I use the CPrintDialog class to select the printer, and subsequently I get a HDC by “CPrintDialog Print.CreatePrinterDC ();” Then I calculate the size on paper by the following piece of code: POINT point; POINT start; point.x = GetDeviceCaps (hDC, PHYSICALWIDTH); start.x = GetDeviceCaps (hDC, PHYSICALOFFSETX); point.x -= (start.x*2); point.y = GetDeviceCaps (hDC, PHYSICALHEIGHT); start.y = GetDeviceCaps (hDC, PHYSICALOFFSETY); point.y -= (start.y*2); DPtoLP (hDC, &point, 1); DPtoLP (hDC, &start, 1); I already have a POINT named “Source”, that holds the size of the screen DC. Then I call: if (!StretchBlt (hDC, start.x, start.y, point.x, point.y, m_pDC->GetSafeHwnd (), 0, 0, Source.x, Source.y, SRCCOPY)) And this is where all goes wrong! This fails, and the error message (as obtained by FormatMessage and GetLastError) says: “The parameter is incorrect” As far as I can see, the size on paper is correct, since I also write a (test) rectangle with these positions: Rectangle (hDC, start.x, start.y, point.x, point.y); and this produces a rectangle on paper with the size and position as I would expect. Can anyone help me out here. William -- modified at 7:29 Thursday 17th August, 2006

      S Offline
      S Offline
      Sarath C
      wrote on last edited by
      #2

      http://www.codeproject.com/tools/screen_snaper.asp[^] check the above link

      SaRath.
      _"Before you can learn to recognize what's wrong, you must learn to recognize what's right" - Raymond Chen."


      My Blog | Understanding State Pattern_

      W 1 Reply Last reply
      0
      • S Sarath C

        http://www.codeproject.com/tools/screen_snaper.asp[^] check the above link

        SaRath.
        _"Before you can learn to recognize what's wrong, you must learn to recognize what's right" - Raymond Chen."


        My Blog | Understanding State Pattern_

        W Offline
        W Offline
        Wim Engberts
        wrote on last edited by
        #3

        Sarath, Thanks for the tip. I checked the link, but it does not solve my problem, since it does not refer to sending the captured image to the printer. I do have a device context with a valid image. However, when I try to copy this image into a printer device context (using StretchBlt), I get an error message. William

        S 1 Reply Last reply
        0
        • W Wim Engberts

          I am writing a graphic design tool. I am using a device context to produce the image on screen. Now I want to be able to print the image to the printer. What I am doing so far is: Create the screen device context : CDC *m_pDC = CreateDC (); Do all kinds of weird and wonderful things to produce the image (all of this works, since I do get the image I want on screen) When the user presses the Print option from the menu, I use the CPrintDialog class to select the printer, and subsequently I get a HDC by “CPrintDialog Print.CreatePrinterDC ();” Then I calculate the size on paper by the following piece of code: POINT point; POINT start; point.x = GetDeviceCaps (hDC, PHYSICALWIDTH); start.x = GetDeviceCaps (hDC, PHYSICALOFFSETX); point.x -= (start.x*2); point.y = GetDeviceCaps (hDC, PHYSICALHEIGHT); start.y = GetDeviceCaps (hDC, PHYSICALOFFSETY); point.y -= (start.y*2); DPtoLP (hDC, &point, 1); DPtoLP (hDC, &start, 1); I already have a POINT named “Source”, that holds the size of the screen DC. Then I call: if (!StretchBlt (hDC, start.x, start.y, point.x, point.y, m_pDC->GetSafeHwnd (), 0, 0, Source.x, Source.y, SRCCOPY)) And this is where all goes wrong! This fails, and the error message (as obtained by FormatMessage and GetLastError) says: “The parameter is incorrect” As far as I can see, the size on paper is correct, since I also write a (test) rectangle with these positions: Rectangle (hDC, start.x, start.y, point.x, point.y); and this produces a rectangle on paper with the size and position as I would expect. Can anyone help me out here. William -- modified at 7:29 Thursday 17th August, 2006

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          some devices cannot handle large bitmaps (see GetDeviceCaps(...RASTERCAPS), so you have to do your output in bands. some devices cannot do StretchBlt or StretchDIBits (again, see GetDeviceCaps)

          image processing | blogging

          1 Reply Last reply
          0
          • W Wim Engberts

            I am writing a graphic design tool. I am using a device context to produce the image on screen. Now I want to be able to print the image to the printer. What I am doing so far is: Create the screen device context : CDC *m_pDC = CreateDC (); Do all kinds of weird and wonderful things to produce the image (all of this works, since I do get the image I want on screen) When the user presses the Print option from the menu, I use the CPrintDialog class to select the printer, and subsequently I get a HDC by “CPrintDialog Print.CreatePrinterDC ();” Then I calculate the size on paper by the following piece of code: POINT point; POINT start; point.x = GetDeviceCaps (hDC, PHYSICALWIDTH); start.x = GetDeviceCaps (hDC, PHYSICALOFFSETX); point.x -= (start.x*2); point.y = GetDeviceCaps (hDC, PHYSICALHEIGHT); start.y = GetDeviceCaps (hDC, PHYSICALOFFSETY); point.y -= (start.y*2); DPtoLP (hDC, &point, 1); DPtoLP (hDC, &start, 1); I already have a POINT named “Source”, that holds the size of the screen DC. Then I call: if (!StretchBlt (hDC, start.x, start.y, point.x, point.y, m_pDC->GetSafeHwnd (), 0, 0, Source.x, Source.y, SRCCOPY)) And this is where all goes wrong! This fails, and the error message (as obtained by FormatMessage and GetLastError) says: “The parameter is incorrect” As far as I can see, the size on paper is correct, since I also write a (test) rectangle with these positions: Rectangle (hDC, start.x, start.y, point.x, point.y); and this produces a rectangle on paper with the size and position as I would expect. Can anyone help me out here. William -- modified at 7:29 Thursday 17th August, 2006

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #5

            Engberts wrote:

            if (!StretchBlt (hDC, start.x, start.y, point.x, point.y, m_pDC->GetSafeHwnd (), 0, 0, Source.x, Source.y, SRCCOPY))

            6th parameter of API is HDC,whats is m_pDC->GetSafeHwnd ()? I guess you are passing incorrect type of parameter. It should HDC(source).

            Prasad Notifier using ATL

            W 1 Reply Last reply
            0
            • P prasad_som

              Engberts wrote:

              if (!StretchBlt (hDC, start.x, start.y, point.x, point.y, m_pDC->GetSafeHwnd (), 0, 0, Source.x, Source.y, SRCCOPY))

              6th parameter of API is HDC,whats is m_pDC->GetSafeHwnd ()? I guess you are passing incorrect type of parameter. It should HDC(source).

              Prasad Notifier using ATL

              W Offline
              W Offline
              Wim Engberts
              wrote on last edited by
              #6

              Sorry, this is a typing error, I of course used GetSafeHdc () and not GetSafeHwnd (). Meanwhile however, I think I found the solution. Since I am copying bitmaps between diferrent devices, I cannot directly BitBlt or StretchBlt between them. I am now using GetDIBits to get the device independant bits out of the screen's device context and then use StretchDIBits to move them into the printer's device context. This does require a lot of programming, but it does result in the required image on paper. Thanks to you all for your efforts! William

              P 1 Reply Last reply
              0
              • W Wim Engberts

                Sarath, Thanks for the tip. I checked the link, but it does not solve my problem, since it does not refer to sending the captured image to the printer. I do have a device context with a valid image. However, when I try to copy this image into a printer device context (using StretchBlt), I get an error message. William

                S Offline
                S Offline
                Sarath C
                wrote on last edited by
                #7

                Before using stretchblt, i think you need to set SetStretchBltMode printing to DC is not a big deal. it's same as using CDC

                SaRath.
                _"Before you can learn to recognize what's wrong, you must learn to recognize what's right" - Raymond Chen."


                My Blog | Understanding State Pattern_

                1 Reply Last reply
                0
                • W Wim Engberts

                  Sorry, this is a typing error, I of course used GetSafeHdc () and not GetSafeHwnd (). Meanwhile however, I think I found the solution. Since I am copying bitmaps between diferrent devices, I cannot directly BitBlt or StretchBlt between them. I am now using GetDIBits to get the device independant bits out of the screen's device context and then use StretchDIBits to move them into the printer's device context. This does require a lot of programming, but it does result in the required image on paper. Thanks to you all for your efforts! William

                  P Offline
                  P Offline
                  prasad_som
                  wrote on last edited by
                  #8

                  Never mind. Importantly, you shared your solution, that's great !

                  Prasad Notifier using ATL

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups