在静态图片中缩放位图 [英] Scaling a bitmap in a static picture
本文介绍了在静态图片中缩放位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了上帝的缘故
当然必须有一种简单的方法来获取位图(从文件加载)以适应在静态图片控件中?
如何??
这是我成功将位图放入静态控件的代码。但是我找不到任何方法(对我来说有用)来缩放位图。
void CGregsLaserEngraverDlg :: LoadBitmap()
{{ if(!m_strFilename.IsEmpty())
  {
       CBitmap bmp;
    HBITMAP hBitmap =(HBITMAP):: LoadImage(AfxGetInstanceHandle(),m_strFolder +" \\" + m_strFilename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_VGACOLOR);
        bmp.Attach(HBITMAP);
         m_staticBMP.SetBitmap(BMP);
       BITMAP位图;
      bmp.GetBitmap(安培;位图);
        的UpdateData(假);
   }
}
我尝试了这种事情,但它对显示的位图没有影响:
CDC * pDC = GetDC(),dc;
CRect rect;
CBitmap bmpScaled,* pBMPScaled = NULL;
m_staticBMP.GetClientRect(rect);
dc.CreateCompatibleDC(pDC);
bmpScaled.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
pBMPScaled = dc.SelectObject(& bmpScaled);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),& dc,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
//dc.SelectObject(pob);
// Bitmap_.SetBitmap((HBITMAP)scale_bitmap.Detach());
ReleaseDC(pDC);
解决方案
你好,
看看这个类:
https://www.codeproject.com/Articles/1300/CxImage
For god sake
Surely there must be a SIMPLE way to get a bitmap (loaded from a file) to fit within a static picture control?
How??
This is the code I have that successfully puts the bitmap into the static control. But I can't find any way (that works for me) to scale the bitmap.
void CGregsLaserEngraverDlg::LoadBitmap()
{
if (!m_strFilename.IsEmpty())
{
CBitmap bmp;
HBITMAP hBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), m_strFolder + "\\" + m_strFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_VGACOLOR);
bmp.Attach(hBitmap);
m_staticBMP.SetBitmap(bmp);
BITMAP bitmap;
bmp.GetBitmap(&bitmap);
UpdateData(false);
}
}
I have tried this sort of thing but it has not effect what so ever on the displayed bitmap:
CDC *pDC = GetDC(), dc; CRect rect; CBitmap bmpScaled, *pBMPScaled = NULL; m_staticBMP.GetClientRect(rect); dc.CreateCompatibleDC(pDC); bmpScaled.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()); pBMPScaled = dc.SelectObject(&bmpScaled); dc.StretchBlt(0, 0, rect.Width(), rect.Height(), &dc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY); //dc.SelectObject(pob); //Bitmap_.SetBitmap((HBITMAP)scale_bitmap.Detach()); ReleaseDC(pDC);
解决方案
Hello,
have a look at this class: https://www.codeproject.com/Articles/1300/CxImage
这篇关于在静态图片中缩放位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文