MFC如何修改BMP图片的大小

2014-03-10 12:52:40 · 作者: · 浏览: 83

  MFC可以在加载图片的时候修改图片大小,我用的一个函数是:

  HANDLE LoadImage(

  HINSTANCE hinst,   // handle to instance

  LPCTSTR lpszName,  // name or identifier of the image

  UINT uType,        // image type

  int cxDesired,     // desired width

  int cyDesired,     // desired height

  UINT fuLoad        // load options

  );

  为了方便期间,我把他配置成我需要的宏定义:

  #define HBMP(filepath,width,height) (HBITMAP)LoadImage(AfxGetInstanceHandle(),filepath,IMAGE_BITMAP,width,height,LR_LOADFROMFILE|LR_CREATEDIBSECTION)

  使用的时候:

  this->GetClientRect(&rect);

  rect.SetRect(rect.left,rect.top+50,rect.right,rect.top+150);

  p_picture = new CStatic;

  p_picture->Create("",WS_VISIBLE|SS_BITMAP,rect,this,IDC_STATIC_PICTURE);

  SwitchJpegToBmp();

  HBITMAP h_bitmap = HBMP("./res/res.bmp",rect.right,50);

  p_picture->SetBitmap(h_bitmap);

  有时候我们需要CBitmap变量:我们可以用Attach克隆一个;