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 display the Bitmap that created by CreateBitmap function?

How to display the Bitmap that created by CreateBitmap function?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiongraphicsperformancetutorial
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.
  • V vasu_sri

    how can i display the bitmap on ListView using CreateBitmap function? void CThumbBmpView::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CListView::OnPaint() for painting messages CRect r; GetClientRect(&r); // Paint to a memory device context to help // eliminate screen flicker. CXTPBufferDC memDC(dc, r); memDC.FillSolidRect(r, (RGB(255,255,255))); OnPrepareDC(&memDC); OnDraw(&memDC); } void CThumbBmpView::OnDraw(CDC* pDC) { // TODO: Add your specialized code here and/or call the base class HANDLE hFile; DWORD dwNumberOfBytesToRead; DWORD dwNumberOfBytesRead; hFile = CreateFile( "D:\\preview.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( hFile == INVALID_HANDLE_VALUE ) { MessageBox( "Invalid Handle", "ERROR", MB_ICONERROR); } else { // MessageBox( "File Opened successfully"); BYTE *Buffer; DWORD p=SetFilePointer( hFile, 0x000, NULL, FILE_BEGIN ); Buffer = new BYTE [2363392+1]; BOOL bResult = ReadFile( hFile, Buffer, // nNumberOfBytesToRead, //specify the file size. 2363392, &dwNumberOfBytesRead, // NULL ); if(!bResult) MessageBox("Error"); //bmp.bmType =0; //bmp.bmWidth =32; //bmp.bmHeight =32; //bmp.bmWidthBytes=1024; //bmp.bmPlanes =2; //bmp.bmBitsPixel =32; //bmp.bmBits =Buffer; if(!bitmap.CreateBitmap(1000,500,1,32,Buffer)) MessageBox("cant Create Bitmap"); } CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( pDC ) ) { return; } CBitmap* pOld = dcCompatible.SelectObject( &bitmap ); BITMAP bmInfo; if ( bitmap.GetObject( sizeof( bmInfo ), &bmInfo ) != 0 ) { pDC->BitBlt( 0,0, bmInfo.bmWidth, bmInfo.bmHeight, &dcCompatible, 0,0, SRCCOPY ); //pDC->StretchBlt(0,0,100,90,&dcCompatible,10,10,110,100, 32); } dcCompatible.SelectObject( pOld ); }

    Regards, Srinivas

    N Offline
    N Offline
    Naveen
    wrote on last edited by
    #2

    vasu_sri wrote:

    CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( pDC ) )

    this will not work. Yous should pass the pointer of original device context. it can be modified as follows CClientDc dc(this) CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( &dc ) )

    nave

    CPalliniC 1 Reply Last reply
    0
    • V vasu_sri

      how can i display the bitmap on ListView using CreateBitmap function? void CThumbBmpView::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CListView::OnPaint() for painting messages CRect r; GetClientRect(&r); // Paint to a memory device context to help // eliminate screen flicker. CXTPBufferDC memDC(dc, r); memDC.FillSolidRect(r, (RGB(255,255,255))); OnPrepareDC(&memDC); OnDraw(&memDC); } void CThumbBmpView::OnDraw(CDC* pDC) { // TODO: Add your specialized code here and/or call the base class HANDLE hFile; DWORD dwNumberOfBytesToRead; DWORD dwNumberOfBytesRead; hFile = CreateFile( "D:\\preview.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( hFile == INVALID_HANDLE_VALUE ) { MessageBox( "Invalid Handle", "ERROR", MB_ICONERROR); } else { // MessageBox( "File Opened successfully"); BYTE *Buffer; DWORD p=SetFilePointer( hFile, 0x000, NULL, FILE_BEGIN ); Buffer = new BYTE [2363392+1]; BOOL bResult = ReadFile( hFile, Buffer, // nNumberOfBytesToRead, //specify the file size. 2363392, &dwNumberOfBytesRead, // NULL ); if(!bResult) MessageBox("Error"); //bmp.bmType =0; //bmp.bmWidth =32; //bmp.bmHeight =32; //bmp.bmWidthBytes=1024; //bmp.bmPlanes =2; //bmp.bmBitsPixel =32; //bmp.bmBits =Buffer; if(!bitmap.CreateBitmap(1000,500,1,32,Buffer)) MessageBox("cant Create Bitmap"); } CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( pDC ) ) { return; } CBitmap* pOld = dcCompatible.SelectObject( &bitmap ); BITMAP bmInfo; if ( bitmap.GetObject( sizeof( bmInfo ), &bmInfo ) != 0 ) { pDC->BitBlt( 0,0, bmInfo.bmWidth, bmInfo.bmHeight, &dcCompatible, 0,0, SRCCOPY ); //pDC->StretchBlt(0,0,100,90,&dcCompatible,10,10,110,100, 32); } dcCompatible.SelectObject( pOld ); }

      Regards, Srinivas

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #3

      In addition to the above post, you must bitblit the content from memdc to dc in the CThumbBmpView::OnPaint()function after the statement OnDraw(&memDC);

      nave

      CPalliniC 1 Reply Last reply
      0
      • N Naveen

        vasu_sri wrote:

        CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( pDC ) )

        this will not work. Yous should pass the pointer of original device context. it can be modified as follows CClientDc dc(this) CDC dcCompatible; if ( !dcCompatible.CreateCompatibleDC( &dc ) )

        nave

        CPalliniC Online
        CPalliniC Online
        CPallini
        wrote on last edited by
        #4

        I don't think this is the problem. Actually I don't think it is a problem.

        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.

        In testa che avete, signor di Ceprano?

        N 1 Reply Last reply
        0
        • N Naveen

          In addition to the above post, you must bitblit the content from memdc to dc in the CThumbBmpView::OnPaint()function after the statement OnDraw(&memDC);

          nave

          CPalliniC Online
          CPalliniC Online
          CPallini
          wrote on last edited by
          #5

          I agree only on this (see my reply above). Additionally, the OP have to first select the bitmap inside the memDC. To summarize, the OP has to: (1) Create a compatible (memory) DC (2) Select the bitmap inside the memory DC. (3) Preform Perform BitBlt from the MemDC to the actual one. Hope that helps :)

          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.

          In testa che avete, signor di Ceprano?

          N 1 Reply Last reply
          0
          • CPalliniC CPallini

            I agree only on this (see my reply above). Additionally, the OP have to first select the bitmap inside the memDC. To summarize, the OP has to: (1) Create a compatible (memory) DC (2) Select the bitmap inside the memory DC. (3) Preform Perform BitBlt from the MemDC to the actual one. Hope that helps :)

            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.

            N Offline
            N Offline
            Naveen
            wrote on last edited by
            #6

            CPallini wrote:

            (1) Create a compatible (memory) DC (2) Select the bitmap inside the memory DC.

            I think the CXTPBufferDC will be hadling this.

            nave

            V 1 Reply Last reply
            0
            • CPalliniC CPallini

              I don't think this is the problem. Actually I don't think it is a problem.

              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.

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #7

              I bet itwill not work unless you change it.

              nave

              CPalliniC 1 Reply Last reply
              0
              • N Naveen

                CPallini wrote:

                (1) Create a compatible (memory) DC (2) Select the bitmap inside the memory DC.

                I think the CXTPBufferDC will be hadling this.

                nave

                V Offline
                V Offline
                vasu_sri
                wrote on last edited by
                #8

                i did all what u asked me to do. i converted CDC to CClientDc. But still it doesn't work. i am doing this for the first time and so can u please explain me a little more clearly?? or can u give me any related link that can help me???

                Regards, Srinivas

                N 1 Reply Last reply
                0
                • N Naveen

                  I bet itwill not work unless you change it.

                  nave

                  CPalliniC Online
                  CPalliniC Online
                  CPallini
                  wrote on last edited by
                  #9

                  And why? :)

                  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.

                  In testa che avete, signor di Ceprano?

                  N 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    And why? :)

                    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.

                    N Offline
                    N Offline
                    Naveen
                    wrote on last edited by
                    #10

                    try for your self..

                    nave

                    CPalliniC 1 Reply Last reply
                    0
                    • V vasu_sri

                      i did all what u asked me to do. i converted CDC to CClientDc. But still it doesn't work. i am doing this for the first time and so can u please explain me a little more clearly?? or can u give me any related link that can help me???

                      Regards, Srinivas

                      N Offline
                      N Offline
                      Naveen
                      wrote on last edited by
                      #11

                      if(!bitmap.CreateBitmap(1000,500,1,32,Buffer)) The bitmap file not only contains the pixel data information. It also contain a file header. But the CreateBitmap funtion only need bufffer information. So you must remove the header information from the buffer before passing it to CreateBitmap function. But still I dont understand why you directly read the bitmap. My suggestion is to use the LoadImage() instead of this.

                      nave

                      V 1 Reply Last reply
                      0
                      • N Naveen

                        if(!bitmap.CreateBitmap(1000,500,1,32,Buffer)) The bitmap file not only contains the pixel data information. It also contain a file header. But the CreateBitmap funtion only need bufffer information. So you must remove the header information from the buffer before passing it to CreateBitmap function. But still I dont understand why you directly read the bitmap. My suggestion is to use the LoadImage() instead of this.

                        nave

                        V Offline
                        V Offline
                        vasu_sri
                        wrote on last edited by
                        #12

                        Naveen R wrote:

                        But still I dont understand why you directly read the bitmap. My suggestion is to use the LoadImage() instead of this.

                        its because i don't have the File name or the file path with me. i just have the addresses of the starting sector and ending sector of the image file to work with. i am then reading the data between those sectors (which is nothing but the data of the image file) into a buffer. now i want to show the preview of that image by just using the data in the buffer before storing it as a file. i am still not able to succeed in what i am trying to do.

                        Regards, Srinivas

                        N 1 Reply Last reply
                        0
                        • V vasu_sri

                          Naveen R wrote:

                          But still I dont understand why you directly read the bitmap. My suggestion is to use the LoadImage() instead of this.

                          its because i don't have the File name or the file path with me. i just have the addresses of the starting sector and ending sector of the image file to work with. i am then reading the data between those sectors (which is nothing but the data of the image file) into a buffer. now i want to show the preview of that image by just using the data in the buffer before storing it as a file. i am still not able to succeed in what i am trying to do.

                          Regards, Srinivas

                          N Offline
                          N Offline
                          Naveen
                          wrote on last edited by
                          #13

                          pls check the article http://www.codeproject.com/bitmap/graphicsuite.asp[^] it have code for reading a bitmap file...

                          nave

                          1 Reply Last reply
                          0
                          • N Naveen

                            try for your self..

                            nave

                            CPalliniC Online
                            CPalliniC Online
                            CPallini
                            wrote on last edited by
                            #14

                            Good (though empirical) point. I will try... :)

                            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.

                            In testa che avete, signor di Ceprano?

                            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