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. Load Bitmap from file to doc

Load Bitmap from file to doc

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelp
14 Posts 3 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.
  • A Amin Abdi

    HBITMAP hBitmap = 0;
    hBitmap = (HBITMAP)LoadImage( NULL,
    pDoc->cInfo.strContractBrand, //file location
    IMAGE_BITMAP,
    0,
    0,
    LR_LOADFROMFILE | LR_DEFAULTSIZE);
    CBitmap Bitmap;
    Bitmap.Attach( hBitmap );

    BITMAP BitmapInfo = { 0 };
    Bitmap.GetBitmap( &BitmapInfo );
    
    DWORD BitmapImageSize = BitmapInfo.bmHeight \*
    	BitmapInfo.bmWidth \*
    	( BitmapInfo.bmBitsPixel / 8 );
    
    BYTE\* pBitmapData = new BYTE\[ BitmapImageSize \];
    ZeroMemory( pBitmapData, BitmapImageSize );
    
    Bitmap.SetBitmapBits(BitmapImageSize, pBitmapData);
    
    Bitmap.SetBitmapBits( BitmapImageSize, pBitmapData );
    
    pDC->SelectObject(&Bitmap);
    pDC->BitBlt(1280, -1765, 390,  -230, pDC, // pDC : a CDC pointer to document (SDI Program)
    0, 0, SRCCOPY);
    
    delete pBitmapData;
    pBitmapData = 0;
    

    purpose: i want to load a bitmap from file and insert in document. the file location is in C..Doc and PDoc is pointer to its document. MapMode is MM_LOMETRIC. problem: it dosen't show anything.:mad::confused: i don't see anything in desired coordinate and print blank page. notice: i find these codes in web and didn't work with CBitmap class. even didn't use bitmap in my programs.

    C Offline
    C Offline
    Cedric Moonen
    wrote on last edited by
    #2

    Your question is very unclear. What is this document you are talking about ? The document class from an SDI app ? If yes, a document class is not something visible, it is supposed to be data only. Are you talking about the view ? Furthermore, what is this pDC you are using in your code snippet ? Where did you put this code ?

    Cédric Moonen Software developer
    Charting control [v2.0] OpenGL game tutorial in C++

    A 1 Reply Last reply
    0
    • A Amin Abdi

      HBITMAP hBitmap = 0;
      hBitmap = (HBITMAP)LoadImage( NULL,
      pDoc->cInfo.strContractBrand, //file location
      IMAGE_BITMAP,
      0,
      0,
      LR_LOADFROMFILE | LR_DEFAULTSIZE);
      CBitmap Bitmap;
      Bitmap.Attach( hBitmap );

      BITMAP BitmapInfo = { 0 };
      Bitmap.GetBitmap( &BitmapInfo );
      
      DWORD BitmapImageSize = BitmapInfo.bmHeight \*
      	BitmapInfo.bmWidth \*
      	( BitmapInfo.bmBitsPixel / 8 );
      
      BYTE\* pBitmapData = new BYTE\[ BitmapImageSize \];
      ZeroMemory( pBitmapData, BitmapImageSize );
      
      Bitmap.SetBitmapBits(BitmapImageSize, pBitmapData);
      
      Bitmap.SetBitmapBits( BitmapImageSize, pBitmapData );
      
      pDC->SelectObject(&Bitmap);
      pDC->BitBlt(1280, -1765, 390,  -230, pDC, // pDC : a CDC pointer to document (SDI Program)
      0, 0, SRCCOPY);
      
      delete pBitmapData;
      pBitmapData = 0;
      

      purpose: i want to load a bitmap from file and insert in document. the file location is in C..Doc and PDoc is pointer to its document. MapMode is MM_LOMETRIC. problem: it dosen't show anything.:mad::confused: i don't see anything in desired coordinate and print blank page. notice: i find these codes in web and didn't work with CBitmap class. even didn't use bitmap in my programs.

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #3

      Amin.Abdi wrote:

      pDC->BitBlt(1280, -1765, 390, -230, pDC, // pDC : a CDC pointer to document (SDI Program) 0, 0, SRCCOPY);

      What is the purpose of bit-blitting from pDC to pDC itself?

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      A 1 Reply Last reply
      0
      • C Cedric Moonen

        Your question is very unclear. What is this document you are talking about ? The document class from an SDI app ? If yes, a document class is not something visible, it is supposed to be data only. Are you talking about the view ? Furthermore, what is this pDC you are using in your code snippet ? Where did you put this code ?

        Cédric Moonen Software developer
        Charting control [v2.0] OpenGL game tutorial in C++

        A Offline
        A Offline
        Amin Abdi
        wrote on last edited by
        #4

        sry forget it the code is in C..View and pdc defined there. program is SDI

        1 Reply Last reply
        0
        • C CPallini

          Amin.Abdi wrote:

          pDC->BitBlt(1280, -1765, 390, -230, pDC, // pDC : a CDC pointer to document (SDI Program) 0, 0, SRCCOPY);

          What is the purpose of bit-blitting from pDC to pDC itself?

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          A Offline
          A Offline
          Amin Abdi
          wrote on last edited by
          #5

          dcMem.SelectObject(&Bitmap);
          pDC->BitBlt(1280, nYposChange-1765, 390, -230, &dcMem, 0, 0, SRCCOPY);

          fixed but still nothing :(

          C 1 Reply Last reply
          0
          • A Amin Abdi

            dcMem.SelectObject(&Bitmap);
            pDC->BitBlt(1280, nYposChange-1765, 390, -230, &dcMem, 0, 0, SRCCOPY);

            fixed but still nothing :(

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #6

            What's the purtpose of a negative height? :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            A 1 Reply Last reply
            0
            • C CPallini

              What's the purtpose of a negative height? :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              A Offline
              A Offline
              Amin Abdi
              wrote on last edited by
              #7

              ;P because of MapMode

              modified on Wednesday, August 26, 2009 4:45 AM

              C 1 Reply Last reply
              0
              • A Amin Abdi

                ;P because of MapMode

                modified on Wednesday, August 26, 2009 4:45 AM

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #8

                And why do you need the following statements?

                Amin.Abdi wrote:

                BYTE* pBitmapData = new BYTE[ BitmapImageSize ]; ZeroMemory( pBitmapData, BitmapImageSize ); Bitmap.SetBitmapBits(BitmapImageSize, pBitmapData); Bitmap.SetBitmapBits( BitmapImageSize, pBitmapData );

                :) The last line is because you don't trust MFC? :rolleyes:

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                A 1 Reply Last reply
                0
                • C CPallini

                  And why do you need the following statements?

                  Amin.Abdi wrote:

                  BYTE* pBitmapData = new BYTE[ BitmapImageSize ]; ZeroMemory( pBitmapData, BitmapImageSize ); Bitmap.SetBitmapBits(BitmapImageSize, pBitmapData); Bitmap.SetBitmapBits( BitmapImageSize, pBitmapData );

                  :) The last line is because you don't trust MFC? :rolleyes:

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  A Offline
                  A Offline
                  Amin Abdi
                  wrote on last edited by
                  #9

                  I change my codes : remove that statement and add these:

                  CClientDC dcMem;
                  dcMem.SelectObject(&Bitmap);
                  pDC->BitBlt(1280, nYposChange-1995, 390, 230, &dcMem, 0, 0, SRCCOPY);
                  

                  but it show a print screen of window and print nothing. WHY and how can i fix it?

                  C 1 Reply Last reply
                  0
                  • A Amin Abdi

                    I change my codes : remove that statement and add these:

                    CClientDC dcMem;
                    dcMem.SelectObject(&Bitmap);
                    pDC->BitBlt(1280, nYposChange-1995, 390, 230, &dcMem, 0, 0, SRCCOPY);
                    

                    but it show a print screen of window and print nothing. WHY and how can i fix it?

                    C Offline
                    C Offline
                    CPallini
                    wrote on last edited by
                    #10

                    You should put your drawing code inside the CView::OnDraw method. :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    A 1 Reply Last reply
                    0
                    • C CPallini

                      You should put your drawing code inside the CView::OnDraw method. :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      A Offline
                      A Offline
                      Amin Abdi
                      wrote on last edited by
                      #11

                      i put it on a function and call the function in C..View::OnDraw.

                      C 1 Reply Last reply
                      0
                      • A Amin Abdi

                        i put it on a function and call the function in C..View::OnDraw.

                        C Offline
                        C Offline
                        CPallini
                        wrote on last edited by
                        #12

                        I would do this test:

                        CDC memDC;
                        memDC.CreateCompatibleDC(pDC);
                        dcMem.SelectObject(&Bitmap);
                        pDC->BitBlt(0, 0, 390, 230, &dcMem, 0, 0, SRCCOPY);

                        :)

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        A 1 Reply Last reply
                        0
                        • C CPallini

                          I would do this test:

                          CDC memDC;
                          memDC.CreateCompatibleDC(pDC);
                          dcMem.SelectObject(&Bitmap);
                          pDC->BitBlt(0, 0, 390, 230, &dcMem, 0, 0, SRCCOPY);

                          :)

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                          [My articles]

                          A Offline
                          A Offline
                          Amin Abdi
                          wrote on last edited by
                          #13

                          THANX :rose:

                          C 1 Reply Last reply
                          0
                          • A Amin Abdi

                            THANX :rose:

                            C Offline
                            C Offline
                            CPallini
                            wrote on last edited by
                            #14

                            You are welcome. As about negative height, when you should make something work, I suggest the 'stay simple' principle: start trying with 'fail-proof' parameters and then, when it works a bit, began to change.. :)

                            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                            [My articles]

                            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