Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   How adjust image to a picture box ? (http://www.go4expert.com/forums/adjust-image-picture-box-t7687/)

xara 3Dec2007 18:17

How adjust image to a picture box ?
 
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.


All times are GMT +5.5. The time now is 04:09.