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. How to copy from CBitmap to CBitmap

How to copy from CBitmap to CBitmap

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorialannouncement
17 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.
  • T ThatsAlok

    V_shr wrote:

    bmp2->Canvas->Draw(0,0,bmp3);

    Where is Canvas variable Situated?

    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

    cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

    H Offline
    H Offline
    Hamid Taebi
    wrote on last edited by
    #6

    Hi ThatsAlok, maybe in future:-D_**


    **_

    whitesky


    T 1 Reply Last reply
    0
    • V V_shr

      you are speaking about CBitmap , do you mean Graphics::TBitmap ???

      G Offline
      G Offline
      gomez_a
      wrote on last edited by
      #7

      I mean the MFC library and the CBitmap class (Visual Studio). regards mwgomez

      1 Reply Last reply
      0
      • T ThatsAlok

        gomez_a wrote:

        CBitmap bmp1, CBitmap bmp2

        what about CBitmap* PASCAL FromHandle( HBITMAP hBitmap)

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

        G Offline
        G Offline
        gomez_a
        wrote on last edited by
        #8

        Please, give me a suggest: How can I get a HBITMAP, when I have only CBitmap bmp3? I found an example: HBITMAP hBitmap = (HBITMAP) ::LoadImage (NULL, lpszPathName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); But, my bmp3 is not from a file. Regards mwgomez

        H T 2 Replies Last reply
        0
        • G gomez_a

          Please, give me a suggest: How can I get a HBITMAP, when I have only CBitmap bmp3? I found an example: HBITMAP hBitmap = (HBITMAP) ::LoadImage (NULL, lpszPathName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); But, my bmp3 is not from a file. Regards mwgomez

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #9

          if you have CBitmap you can use bmp3.m_hObject_**


          **_

          whitesky


          G 1 Reply Last reply
          0
          • H Hamid Taebi

            if you have CBitmap you can use bmp3.m_hObject_**


            **_

            whitesky


            G Offline
            G Offline
            gomez_a
            wrote on last edited by
            #10

            I wrote a class in MFC (MyClass : public CWnd), in this class I have a field CBitmap mBitmap; // not a pointer I set the bitmap using method: SetBitmap(UINT nIDResource) { return m_Bitmap.LoadBitmap(nIDResource); } But now I want to set the bitmap using: SetBitmap(CBitmap *pBitmap); I don't know how to assign (change?) CBitmap *pBitmap to CBitmap mBitmap. This is only a practice, but I want to understand it. Regards

            H 1 Reply Last reply
            0
            • G gomez_a

              Please, give me a suggest: How can I get a HBITMAP, when I have only CBitmap bmp3? I found an example: HBITMAP hBitmap = (HBITMAP) ::LoadImage (NULL, lpszPathName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); But, my bmp3 is not from a file. Regards mwgomez

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #11

              gomez_a wrote:

              How can I get a HBITMAP, when I have only CBitmap bmp3?

              CBitmap::operator HBITMAP

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

              1 Reply Last reply
              0
              • V V_shr

                you are speaking about CBitmap , do you mean Graphics::TBitmap ???

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #12

                V_shr wrote:

                do you mean Graphics::TBitmap ???

                I believe Poster is refering to MFC:: CBitmap (Though MFC is not a namespace)

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                1 Reply Last reply
                0
                • H Hamid Taebi

                  Hi ThatsAlok, maybe in future:-D_**


                  **_

                  whitesky


                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #13

                  WhiteSky wrote:

                  maybe in future:-D

                  I believe in 2106 when our ancestor are codingĀ  (oops thinking):)

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                  H 1 Reply Last reply
                  0
                  • T ThatsAlok

                    WhiteSky wrote:

                    maybe in future:-D

                    I believe in 2106 when our ancestor are codingĀ  (oops thinking):)

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                    cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                    H Offline
                    H Offline
                    Hamid Taebi
                    wrote on last edited by
                    #14

                    2106 but one question why 2106_**


                    **_

                    whitesky


                    1 Reply Last reply
                    0
                    • G gomez_a

                      I wrote a class in MFC (MyClass : public CWnd), in this class I have a field CBitmap mBitmap; // not a pointer I set the bitmap using method: SetBitmap(UINT nIDResource) { return m_Bitmap.LoadBitmap(nIDResource); } But now I want to set the bitmap using: SetBitmap(CBitmap *pBitmap); I don't know how to assign (change?) CBitmap *pBitmap to CBitmap mBitmap. This is only a practice, but I want to understand it. Regards

                      H Offline
                      H Offline
                      Hamid Taebi
                      wrote on last edited by
                      #15

                      I dont understand you have one function SetBitmap(UINT nIDResource) now you want to pass SetBitmap(CBitmap *pBitmap); to this function or your problem CBitmap mBitmap_**


                      **_

                      whitesky


                      G 1 Reply Last reply
                      0
                      • H Hamid Taebi

                        I dont understand you have one function SetBitmap(UINT nIDResource) now you want to pass SetBitmap(CBitmap *pBitmap); to this function or your problem CBitmap mBitmap_**


                        **_

                        whitesky


                        G Offline
                        G Offline
                        gomez_a
                        wrote on last edited by
                        #16

                        Suppose we have a class: class CBitmapViewer : public CWnd { ... public: CBitmap m_Bitmap; // the BMP is loaded here CRect R; // the whole window size public: virtual BOOL Create(CWnd* pParentWnd, const RECT& rect, UINT nID, DWORD dwStyle = WS_VISIBLE); BOOL SetBitmap(UINT nIDResource); }; I am creating the picture 1: CRect RPicture1(10, 10, 200, 200); mPicture1 = new CBitmapViewer(); mPicture1->Create(this, RPicture1, ID_OBRAZEK); mPicture1->SetBitmap(IDB_BITMAP_CHILD); I am creating the picture 2: CRect RPicture2(10, 220, 200, 410); mPicture2 = new CBitmapViewer(); mPicture2->Create(this, RPicture2, ID_OBRAZEK); mPicture2->SetBitmap(IDB_BITMAP_CHILD); There are two picture on the screen. Now the user can mark the part of the first window. This coorinates are placed in CRect Rf. Now, I am cutting down a part of the picture one - using the Rf coordinates: int mWidth = Rf.Width(); int mHeight = Rf.Height(); CBitmap bmp_part; bmp_part.CreateBitmap(mWidth, mHeight, 1, 24, NULL); // get the bitmap size BITMAP bitmap_size; bmp_part.GetObject(sizeof(BITMAP), &bitmap_size); // get a bitmap's part from Picture1 and place them into the bmp_part unsigned char *pData2 = new unsigned char[bitmap_size.bmHeight * bitmap_size.bmWidthBytes]; mPicture1->m_Bitmap.GetBitmapBits(bitmap_size.bmHeight * bitmap_size.bmWidthBytes, pData2); bmp_part.SetBitmapBits(bitmap_size.bmHeight * bitmap_size.bmWidthBytes, pData2); delete[] pData2; /* when I have a part of the Picture1 in the bmp_part a want to replace a Picture2 with bmp_part. */ For example using: mPicture2.Assign(&bmp_part); or I can to create the new object: mNewBitmap = new CBitmapViewer(); mNewBitmap->Create(this, R3, ID_OBRAZEK3); // CRect R3 - where the window is placed mNewBitmap->AssignBitmap(&bmp_part); From this moment I want some help, becouse I don't know how to do it Regards

                        H 1 Reply Last reply
                        0
                        • G gomez_a

                          Suppose we have a class: class CBitmapViewer : public CWnd { ... public: CBitmap m_Bitmap; // the BMP is loaded here CRect R; // the whole window size public: virtual BOOL Create(CWnd* pParentWnd, const RECT& rect, UINT nID, DWORD dwStyle = WS_VISIBLE); BOOL SetBitmap(UINT nIDResource); }; I am creating the picture 1: CRect RPicture1(10, 10, 200, 200); mPicture1 = new CBitmapViewer(); mPicture1->Create(this, RPicture1, ID_OBRAZEK); mPicture1->SetBitmap(IDB_BITMAP_CHILD); I am creating the picture 2: CRect RPicture2(10, 220, 200, 410); mPicture2 = new CBitmapViewer(); mPicture2->Create(this, RPicture2, ID_OBRAZEK); mPicture2->SetBitmap(IDB_BITMAP_CHILD); There are two picture on the screen. Now the user can mark the part of the first window. This coorinates are placed in CRect Rf. Now, I am cutting down a part of the picture one - using the Rf coordinates: int mWidth = Rf.Width(); int mHeight = Rf.Height(); CBitmap bmp_part; bmp_part.CreateBitmap(mWidth, mHeight, 1, 24, NULL); // get the bitmap size BITMAP bitmap_size; bmp_part.GetObject(sizeof(BITMAP), &bitmap_size); // get a bitmap's part from Picture1 and place them into the bmp_part unsigned char *pData2 = new unsigned char[bitmap_size.bmHeight * bitmap_size.bmWidthBytes]; mPicture1->m_Bitmap.GetBitmapBits(bitmap_size.bmHeight * bitmap_size.bmWidthBytes, pData2); bmp_part.SetBitmapBits(bitmap_size.bmHeight * bitmap_size.bmWidthBytes, pData2); delete[] pData2; /* when I have a part of the Picture1 in the bmp_part a want to replace a Picture2 with bmp_part. */ For example using: mPicture2.Assign(&bmp_part); or I can to create the new object: mNewBitmap = new CBitmapViewer(); mNewBitmap->Create(this, R3, ID_OBRAZEK3); // CRect R3 - where the window is placed mNewBitmap->AssignBitmap(&bmp_part); From this moment I want some help, becouse I don't know how to do it Regards

                          H Offline
                          H Offline
                          Hamid Taebi
                          wrote on last edited by
                          #17

                          Hope I understood your question void CAnswerDlg::OnBnClickedTest() { CBitmapViewer *mNewBitmap; CBitmap bmp_part; bmp_part.Attach((HBITMAP)LoadImage(AfxGetInstanceHandle(),"c:\\0.bmp",IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION)); CRect R3; mNewBitmap = new CBitmapViewer(); mNewBitmap->Create(this, R3, 1); // CRect R3 - where the window is placed mNewBitmap->SetBitmap2(&bmp_part); mNewBitmap->DestroyWindow(); /* if you use this code you see one file CImage m; m.Attach(mNewBitmap->m_Bitmap); m.Save("c:\\test.bmp"); m.Detach();*/ } BOOL CBitmapViewer::Create(CWnd* pParentWnd, const RECT& rect,UINT nID,DWORD dwStyle) { return CWnd::Create("CBitmapViewer","",dwStyle,rect,pParentWnd,1,0); } BOOL CBitmapViewer::SetBitmap(UINT nIDResource) { return m_Bitmap.LoadBitmap(nIDResource); } void CBitmapViewer::SetBitmap2(CBitmap *m) { m_Bitmap.Attach((HBITMAP)m->m_hObject); }_**


                          **_

                          whitesky


                          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