How adjust image to a picture box ?

Discussion in 'MFC' started by xara, Dec 3, 2007.

  1. xara

    xara New Member

    Joined:
    Dec 3, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello,

    I am trying to display an image into a PDA but I have no experience programming for PDA's neither working with images. I followed more or less the instructions given in a post from this forum: "Display Bitmap in a Picture Box using MFC from a file". I am working in Microsoft eMbedded C++ 4.0. First, I created a dialog based MFC project and added a Picture Control. Then I added the variable CStatic and load the bitmap. The problem is that it does not fit into the Picture Control place, I mean, the whole image is not displayed. I know that I need the StretchBlt function for adjusting it but I am doing anything wrong and it does not work. I would be very grateful if somebody could help me with this because I have been trying to solve this for a long time and I am desperate. This is the code that I have in OnInitDialog:
    Code:
     
    HBITMAP hBmp; 
     if((hBmp = SHLoadImageFile(_T("\\1_eli.jpg")))!=0x00000000)
     {  
      // Get the dimensions of the bitmap
      CBitmap bmp;
      bmp.Attach(hBmp);
      BITMAP bm;
      bmp.GetBitmap(&bm);  
      bmp.Detach(); 
     
      // dimensions of the control
      RECT rectScaled;
      m_imagen.GetWindowRect(&rectScaled);
      int rectW=rectScaled.right-rectScaled.left;
      int rectH=rectScaled.bottom-rectScaled.top;
     
      HDC hdc=::GetDC(m_imagen.m_hWnd);
      HDC memdc=CreateCompatibleDC(hdc);
     HBITMAP hBmp2=(HBITMAP)SelectObject(memdc,hBmp);
      //HBITMAP hBmp2=CreateCompatibleBitmap(memdc,rectW,rectH);
      //BitBlt(memdc,0,0,150,100,hdc,0,0,SRCCOPY);
      StretchBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,memdc,0,0,rectW,rectH,SRCCOPY);
      //SelectObject(memdc,hBmp2);
     
      m_imagen.SetBitmap(hBmp2);   
        
     }
    Thanks for your time.
     
    Last edited by a moderator: Dec 3, 2007

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice