zoukankan      html  css  js  c++  java
  • MFC加载图片

    1. 自适应方法

    	/* 自适应方法       */
    	CRect rect;
    	CRect rect1;
    
    	CImage image; //创建图片类  
    	image.Load(picname); //根据图片路径加载图片   
    
    
    	//获取Picture Control控件的大小
    	GetDlgItem(IDC_PICTURE)->GetWindowRect(&rect);//将窗口矩形选中到picture控件上  
    	ScreenToClient(&rect);//将客户区选中到Picture控件表示的矩形区域内  
    	GetDlgItem(IDC_PICTURE)->GetClientRect(&rect);
    
    	CWnd *pWnd=GetDlgItem(IDC_PICTURE);//获得pictrue控件窗口的句柄  
    	pWnd->GetClientRect(&rect);//获取句柄指向控件区域的大小  
    
    	CDC *pDC=pWnd->GetDC();//获得pictrue控件的DC  
    
    	SetStretchBltMode(pDC->m_hDC,STRETCH_HALFTONE);
    	if(image.GetWidth()<=rect.Width() && image.GetHeight()<=rect.Width()) //图片小于控件区域,不缩放
    	{
    		rect1 = CRect(rect.TopLeft(), CSize(image.GetWidth(),image.GetHeight()));
    		image.StretchBlt(pDC->m_hDC,rect1,SRCCOPY);//将图片画到Picture控件表示的矩形区域 
    	}
    	else
    	{
    		float xScale=(float)rect.Width()/(float)image.GetWidth();
    		float yScale=(float)rect.Height()/(float)image.GetHeight();
    		float ScaleIndex=(xScale<=yScale? xScale:yScale);
    		rect1 = CRect(rect.TopLeft(), CSize((int)image.GetWidth()*ScaleIndex,(int)image.GetHeight()*ScaleIndex));
    		image.StretchBlt(pDC->m_hDC,rect1,SRCCOPY);//将图片画到Picture控件表示的矩形区域
    	}
    	image.Draw(pDC->m_hDC, rect);//将图片绘制到picture表示的区域内  
    	ReleaseDC(pDC);
    

    2. 加载原图方法

    /* 加载原图的方法*/
        CImage image; //创建图片类  
    	image.Load(picname); //根据图片路径加载图片  
    
    	CRect rect;//定义矩形类  
    	int cx = image.GetWidth();//获取图片宽度  
    	int cy = image.GetHeight();//获取图片高度  
    
    	GetDlgItem(IDC_PICTURE)->GetWindowRect(&rect);//将窗口矩形选中到picture控件上  
    	ScreenToClient(&rect);//将客户区选中到Picture控件表示的矩形区域内  
    	GetDlgItem(IDC_PICTURE)->MoveWindow(rect.left, rect.top, cx, cy, TRUE);//将窗口移动到Picture控件表示的矩形区域  
    
    	CWnd *pWnd=GetDlgItem(IDC_PICTURE);//获得pictrue控件窗口的句柄  
    
    	pWnd->GetClientRect(&rect);//获得pictrue控件所在的矩形区域  
    
    	CDC *pDC=pWnd->GetDC();//获得pictrue控件的DC  
    
    	image.Draw(pDC->m_hDC, rect); //将图片画到Picture控件表示的矩形区域  
    	ReleaseDC(pDC);//释放picture控件的DC  
    
  • 相关阅读:
    CSS3的[att$=val]选择器
    CSS3的[att^=val]选择器
    CSS3的[att*=val]选择器
    CSS3的[att=val]选择器
    web报表工具finereport常用函数的用法总结(数组函数)
    web报表工具finereport常用函数的用法总结(数组函数)
    人性多面性的终极教材——北漂18年(4)
    第23章 MYSQL结构
    11g OS文件移动到ASM
    Oracle 10g TAF配置
  • 原文地址:https://www.cnblogs.com/gaozihan/p/10825468.html
Copyright © 2011-2022 走看看