⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 显示渐变色彩效果.txt

📁 数字图像处理技术源代码
💻 TXT
字号:
//-----------------------------------------------------------------------------
void CGradpalWnd::OnPaint()
{
	CPaintDC dc(this);
	//选中调色板
	CPalette *pPalOld = dc.SelectPalette(&m_Pal, FALSE);
	//实现调色板
	dc.RealizePalette();
	RECT rect;
	//得到客户区的屏幕位置
	this->GetClientRect(&rect);
	//显示位图
	this->PaintGradiantRect(&dc, rect);
	//恢复原来的调色板
	dc.SelectPalette(pPalOld, FALSE);
}
//-----------------------------------------------------------------------------
void CGradpalWnd::PaintGradiantRect(CDC *pDC, const RECT &rect) const
{
	ASSERT(pDC != NULL);
	ASSERT_KINDOF(CDC, pDC);
	//初始化矩形
	RECT rectVar = { rect.left, rect.top, rect.left, rect.top };
	int nTotalSize;
	//查看绘图模式,并设定ntotalSize
	//竖线方向
	if (m_nPaintDir == GPD_TTOB || m_nPaintDir == GPD_BTOT)
	{
		rectVar.right = rect.right;
		nTotalSize = rect.bottom - rect.top;
	}
	//横线方向
	else
	{
		rectVar.bottom = rect.bottom;
		nTotalSize = rect.right - rect.left;
	}
	
	//计算绘制次数
	for (int nIndex = 0; nIndex < m_nPaintSteps; nIndex++)
	{
		//计算矩形
		if (m_nPaintDir == GPD_TTOB || m_nPaintDir == GPD_BTOT)
		{
			rectVar.top = rectVar.bottom;
			rectVar.bottom = rect.top +
				::MulDiv(nIndex + 1, nTotalSize, m_nPaintSteps);
		}
		else
		{
			rectVar.left = rectVar.right;
			rectVar.right = rect.left +
				::MulDiv(nIndex + 1, nTotalSize, m_nPaintSteps);
		}
		
		// 计算颜色值
		int nColor = ::MulDiv(nIndex, 255, m_nPaintSteps);
		if (m_nPaintDir == GPD_BTOT || m_nPaintDir == GPD_RTOL)
			nColor = 255 - nColor;
		const COLORREF clrBr =
			PALETTERGB((BYTE)(m_nPaintRGB & GPC_RED ? nColor : 0),
			(BYTE)(m_nPaintRGB & GPC_GREEN ? nColor : 0),
			(BYTE)(m_nPaintRGB & GPC_BLUE ? nColor : 0));
		// 绘制矩形
		CBrush brush(clrBr);
		pDC->FillRect(&rectVar, &brush);
	}
}
//-----------------------------------------------------------------------------
BOOL CGradpalWnd::CreateGradPalette()
{	
	//已经存在
	if (m_Pal.GetSafeHandle() != NULL)
		return FALSE;
	BOOL bSucc = FALSE;
	//调色板最多可以增加的颜色数目
	const int nNumColors = 236;
	//创建逻辑调色板
	LPLOGPALETTE lpPal = (LPLOGPALETTE)new BYTE[sizeof(LOGPALETTE) +
		sizeof(PALETTEENTRY) *
		nNumColors];
	if (lpPal != NULL)
	{	
		//设定调色板的一些参数
		lpPal->palVersion = 0x300;
		lpPal->palNumEntries = nNumColors;
		PALETTEENTRY *ppe = lpPal->palPalEntry;
		//创建调色板的数据
		for (int nIndex = 0; nIndex < nNumColors; nIndex++)
		{
			const int nColor = ::MulDiv(nIndex, 255, nNumColors);
			ppe->peRed = (BYTE)(m_nPaintRGB & GPC_RED ? nColor : 0);
			ppe->peGreen = (BYTE)(m_nPaintRGB & GPC_GREEN ? nColor : 0);
			ppe->peBlue = (BYTE)(m_nPaintRGB & GPC_BLUE ? nColor : 0);
			ppe->peFlags = (BYTE)0;
			ppe++;
		}
		bSucc = m_Pal.CreatePalette(lpPal);
		delete [](PBYTE)lpPal;
	}
	return bSucc;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -