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. Image Acquisition

Image Acquisition

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearning
6 Posts 3 Posters 8 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.
  • C Offline
    C Offline
    Chambers
    wrote on last edited by
    #1

    Hi all, I am back with yet another question (and its really bugging me!). I have successfully implemented some TWAIN support. That is, I can access the device drivers for the scanner etc. and select a device in the event of there being more than one. I can get the device session manager up too, from where I can get preview the picture etc. and I can actually get it to scan the area I want. However, when it comes to getting this image up onto the screen is where I`m having difficulty. I have looked at Rajiv's wrapper on this very web-site, and its really helped me get this far, however his code is very complicated (with v.few comments) when it comes to displaying the image on the screen, and completely differs from the way that I do it in my program. I create a DIBSection from the BITMAPINFO resource (which I can obtain in my program). However, when I try to create a DIBSECTION it returns a HBITMAP and there is merely a black rectangle(the same size and shape as the one I selected using the DSM after the preview). I have probably got the pointer to bits somewhere too amongst the void* I managed to obtain the BITMAPINFO from, but don`t know what I have to do to get at the right ones and get this blinking DIBSection of a scanned image going. Please help. Cheers guys (for reading all that anyway) Alan.:confused: AEGC

    C 1 Reply Last reply
    0
    • C Chambers

      Hi all, I am back with yet another question (and its really bugging me!). I have successfully implemented some TWAIN support. That is, I can access the device drivers for the scanner etc. and select a device in the event of there being more than one. I can get the device session manager up too, from where I can get preview the picture etc. and I can actually get it to scan the area I want. However, when it comes to getting this image up onto the screen is where I`m having difficulty. I have looked at Rajiv's wrapper on this very web-site, and its really helped me get this far, however his code is very complicated (with v.few comments) when it comes to displaying the image on the screen, and completely differs from the way that I do it in my program. I create a DIBSection from the BITMAPINFO resource (which I can obtain in my program). However, when I try to create a DIBSECTION it returns a HBITMAP and there is merely a black rectangle(the same size and shape as the one I selected using the DSM after the preview). I have probably got the pointer to bits somewhere too amongst the void* I managed to obtain the BITMAPINFO from, but don`t know what I have to do to get at the right ones and get this blinking DIBSection of a scanned image going. Please help. Cheers guys (for reading all that anyway) Alan.:confused: AEGC

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

      how are you creating your DIBSection? -c


      POKE 808,234

      realJSOPR C 2 Replies Last reply
      0
      • C Chris Losinger

        how are you creating your DIBSection? -c


        POKE 808,234

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3

        Ruh roh... :) "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        1 Reply Last reply
        0
        • C Chris Losinger

          how are you creating your DIBSection? -c


          POKE 808,234

          C Offline
          C Offline
          Chambers
          wrote on last edited by
          #4

          I have been creating my DIBSections using CreateDIBSection, as you will know this returns a HBITMAP, and any other pieces of info I may want ("the bits" etc.). However, I have got one step closer to finding a solution to this problem and I feel that your on the right lines Chris. I have now assertained a full BITMAPINFO structure (valid from the scanned image), and I even have a pointer to "the bits". However, my program relies on the HBITMAP structure that I need to create, if I use CreateDIBSection, the pointer I supply to the function is overridden and comes back with just black pixel values. Is there any way I can create the HBITMAP using the BITMAPINFO structure I have got and the pointer to "the bits"? I believe this is this problem is now solveable, but how? Cheers Chris, Alan.:)

          C 1 Reply Last reply
          0
          • C Chambers

            I have been creating my DIBSections using CreateDIBSection, as you will know this returns a HBITMAP, and any other pieces of info I may want ("the bits" etc.). However, I have got one step closer to finding a solution to this problem and I feel that your on the right lines Chris. I have now assertained a full BITMAPINFO structure (valid from the scanned image), and I even have a pointer to "the bits". However, my program relies on the HBITMAP structure that I need to create, if I use CreateDIBSection, the pointer I supply to the function is overridden and comes back with just black pixel values. Is there any way I can create the HBITMAP using the BITMAPINFO structure I have got and the pointer to "the bits"? I believe this is this problem is now solveable, but how? Cheers Chris, Alan.:)

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

            can you show us a bit of your code (like where do you get your DCs from, any SelectObject stuff), etc? =c


            POKE 808,234

            C 1 Reply Last reply
            0
            • C Chris Losinger

              can you show us a bit of your code (like where do you get your DCs from, any SelectObject stuff), etc? =c


              POKE 808,234

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

              OK, I have actually managed to solve the problem, but I`d still appreciate it if you could tell me whether this code is efficient, and if not an alternative approach to solving the problem. The code below is generated from the OnAquisitionClick() function (which does all the TWAIN stuff) and passes the results to the AcquireImage() function, both of which are located in the MainFrame class of an MDI app. right here goes:

              void CMainFrame::AcquireImage(HBITMAP hbitmap, TW_IMAGEINFO& info)
              {
              CBitmapDoc* pBitmapDoc = NewDocument(); //new doc.
              CBitmapFrame* pBitmapWnd = (CBitmapFrame*)NewWindow(pBitmapDoc);

              BYTE* lpVoid, *pBits;
              LPBITMAPINFO pHead;

              lpVoid = (BYTE*)GlobalLock(hbitmap);
              pHead = (LPBITMAPINFO)lpVoid;
              if(pHead->bmiHeader.biCompression != BI_RGB || pHead->bmiHeader.biBitCount != 24)
              {
              GlobalUnlock(lpVoid);
              return;
              }

              pBits = (BYTE*)lpVoid + sizeof(BITMAPINFOHEADER);
              HBITMAP newbitmap = CreateDIBitmap(pBitmapWnd->GetDC()->m_hDC, &pHead->bmiHeader, CBM_INIT, pBits, pHead, DIB_RGBCOLORS);

              if(newbitmap)
              {
              pBitmapDoc->m_hAppliedTools.push_back(newbitmap); //stores all the layers in order for drawing later.
              pBitmapWnd->SetMinMaxWndSize(pHead->bmiHeader.biWidth, pHead->bmiHeader.biHeight);
              pBitmapWnd->AddDYNAMenu(m_hFilters, m_hTools);
              pBitmapDoc->SetTitle("Acquired");
              m_hBitmapTemplate->InitialUpdateFrame(pBitmapWnd, pBitmapDoc, TRUE);
              return;
              }
              else
              AfxMessageBox("Cannot create new image acquisition graphic");

              }

              The one thing I do notice is that although I get all my information from hbitmap, if I try to use that Handle, the image is not drawn at all! I think, now that I`ve got this working, I may be able to figure out some better code to the job (I noticed some areas when I was just typing it out). One other thing, hbitmap may have been ascertained from the scanner as a HANDLE and not a HBITMAP (what I mean by that is that I could pass a HANDLE to one of the TWAIN acquire procedures and it still works). The handle is then passed to the procedure above. Hope you can enlighten/reassure me on my code. Thanks again Chris, Alan:-D "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

              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