Can’t Display Bitmap of Higher Resolution than CDC area

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bruffchewren
    New Member
    • May 2010
    • 5

    Can’t Display Bitmap of Higher Resolution than CDC area

    Hi there dear gurus and expert coders.

    i am not gonna start with im a newbie and don't know much about image programming but unfortunately those are the facts :(

    I am trying to display an image from a bitmap pointer *ImageData which is of resolution 1392x1032. I am trying to draw that at an area of resolution or size 627x474.

    However, repeated trying doesnt seem to work. It works when I change the bitmap image I created from *ImageData width and height to resolution or size of around 627x474

    I really do not know how to solve this after trying all possible solutions from various forums and google.

    pDC is a CDC* and memDC is a CDC initialized in an earlier method Anything uninitialized here was initialized in other methods.

    Here is my code dear humble gurus. Do provide me with guidance Yoda and Obi-Wan provided to Luke Skywalker.

    Code:
    void DemoControl::ShowImage( void *ImageData ) 
    { 
        int Width; //Width of Image From Camera 
        int Height; //Height of Image From Camera 
     
        int m_DisplayWidth = 627 ;//width of rectangle area to display 
        int m_DisplayHeight = 474;//height of rectangle area to display 
     
        GetImageSize( &Width, &Height ) ; //this will return Width = 1392, Height 1032 
    
        CBitmap bitmap; 
        bitmap.CreateBitmap(Width,Height,32,1,ImageData); 
        CBitmap* pOldBitmap = memDC.SelectObject((CBitmap*)&bitmap); 
     
        pDC->BitBlt(22, 24, 627, 474, &memDC, 0, 0, SRCCOPY); 
        memDC.SelectObject((CBitmap*)pOldBitmap); 
        ReleaseDC(pDC); 
     
    }
    Ok heres some additional parts

    I think i should explain how the flow goes.

    (a) A class (lets say DemoTestingDlg class) will pass the CDC as below to another class (lets say DemoControl class)

    m_Demo = new DemoControl ;

    m_Demo->Initialisation ( this, this->GetDC() ) ;

    (b) At the DemoControl class

    bool DemoControl::In itialisation( CDemoTestingDlg *m_FormControl, CDC* m_StaticDisplay ) {

    pDC = m_StaticDisplay ;
    memDC.CreateCom patibleDC(pDC);
    }

    pDC and memDC is as such in the header:

    CDC* pDC ; CDC memDC;
    (c) If lets say an image is captured, the image pointer is passed to the DemoTestingDlg class which will subsequently call a showImage method in the Demo Control Class which is the method I wrote in the question. Am i doing it right?

    Note: It did show an image if lets say they are of the same size (by they i mean the CDC and bitmap) so i was under the impression that my CDC pointer was passed correctly. I have also tried StretchBlt and got the same results.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You haven't said what results you are getting, however as currently written, assuming both DCs are still valid when the method gets called then you should get the top left portion of the bitmap copied to the screen.

    You will need to use StretchBlt to transform the bigger image onto the smaller screen.

    Also what are you doing in the window in response to the WM_PAINT message? The default WM_PAINT handler will clear the window to the background colour. it is normally a mistake to draw outside this handler as anything drawn that way is normally only temporary.

    Comment

    • bruffchewren
      New Member
      • May 2010
      • 5

      #3
      Originally posted by Banfa
      You haven't said what results you are getting, however as currently written, assuming both DCs are still valid when the method gets called then you should get the top left portion of the bitmap copied to the screen.

      You will need to use StretchBlt to transform the bigger image onto the smaller screen.

      Also what are you doing in the window in response to the WM_PAINT message? The default WM_PAINT handler will clear the window to the background colour. it is normally a mistake to draw outside this handler as anything drawn that way is normally only temporary.
      Thanks for the reply banfa. I am having trouble displaying my image of 1392x1032 on the CDC area which is of size 627x474. It works fine if lets say my image is of around 627x474.

      Another question:

      bitmap.CreateBi tmap(Width,Heig ht,32,1,ImageDa ta);
      I am working with a monochrome bitmap therefore in my CreateBitmap
      method, the nPlanes should be '1' and the bitCount should be '8'.(please
      correct me if im wrong)

      However, when I set it as such, my cdc does not display anything and if i put the bitCount as 1, it displays noise whereas anything other than that, I will get nothing.

      Here is what i put for my onpaint method

      void CDemoTestingDlg ::OnPaint()
      {
      if (IsIconic())
      {
      CDC* pDC = GetDC();

      // Select as object(transpar ent brush)
      pDC->SelectStockObj ect(NULL_BRUSH) ;

      // Draw
      pDC->Rectangle(22 , 24, 649, 498);
      ReleaseDC(pDC);
      }
      else
      CDialog::OnPain t();

      }

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Right well I have written several programs that used a memory bitmap image to copy to the actual window.

        However in all of them what I did was store (and write to) the memory image where ever I chose but then having written to the memory image called invalidateRect and have the WM_PAINT handler BitBlt or StretchBlt the memory bitmap onto the screen. That ensures that the window is drawn correctly even if another window is temporarily placed over it.

        I suggest you do the same as it took me several days of experimenting to conclude this was the easiest and simplest way to get the desired behaviour consistently.

        Comment

        • bruffchewren
          New Member
          • May 2010
          • 5

          #5
          Alright i forgot to reply to this! I solved it by using DIB and HDC instead! So if anyone has the same prob can ask me n i'll pass u the codes if you are facing the same prob!

          Comment

          Working...