zoukankan      html  css  js  c++  java
  • MFC Picture Ctrl 无失真自适应显示图片

     1 int height, width;  
     2     CRect rect;//定义矩形类  
     3     CRect rect1;  
     4     CImage image; //创建图片类  
     5     image.Load("test.bmp");  
     6     height = image.GetHeight();  
     7     width = image.GetWidth();  
     8 
     9     m_src.GetClientRect(&rect); //获得pictrue控件所在的矩形区域  
    10     CDC *pDc = m_src.GetDC();//获得pictrue控件的Dc  
    11     SetStretchBltMode(pDc->m_hDC,STRETCH_HALFTONE);   
    12 
    13     if(width<=rect.Width() && height<=rect.Width()) //小图片,不缩放  
    14     {  
    15         rect1 = CRect(rect.TopLeft(), CSize(width,height));  
    16         image.StretchBlt(pDc->m_hDC,rect1,SRCCOPY); //将图片画到Picture控件表示的矩形区域  
    17         return TRUE;  
    18     }  
    19     else  
    20     {  
    21         float xScale=(float)rect.Width()/(float)width;  
    22         float yScale=(float)rect.Height()/(float)height;  
    23         float ScaleIndex=(xScale>=yScale?xScale:yScale);
    24         rect1 = CRect(rect.TopLeft(), CSize((int)width*ScaleIndex,(int)height*ScaleIndex));  
    25         image.StretchBlt(pDc->m_hDC,rect1,SRCCOPY); //将图片画到Picture控件表示的矩形区域  
    26     }  
    27     ReleaseDC(pDc);//释放picture控件的Dc 

    http://blog.sina.com.cn/s/blog_69b5d2a50101a7qf.html

  • 相关阅读:
    开源TinyXML 最简单的新手教程
    2014第14周一开发问题记
    2014第13周日
    140329
    2014第13周五
    2014第13周四Webservice概念问题记
    2014第13周三
    2014第13周二
    2014第13周一
    2014第12周日
  • 原文地址:https://www.cnblogs.com/gaohai/p/5987770.html
Copyright © 2011-2022 走看看