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

📄 virtualcylinder.cpp

📁 visual c++数字图像与图形处理中的光盘内容
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////////
//	
// VirtualCylinder.cpp: implementation of the CVirtualCylinder class.
//
////////////////////////////////////////////////////////////////////////////////
// 版权所有(2002)
// Copyright(2002)
// 编写者: 向世明
// Author: Xiang Shiming


#include "stdafx.h"
#include "VirtualCylinder.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CVirtualCylinder::CVirtualCylinder()
{
	m_byRed = 128;
	m_byGreen = 128;
	m_byBlue = 128;
}

CVirtualCylinder::~CVirtualCylinder()
{}

//设置虚拟圆柱的主体颜色,不要将它的主体颜色设置为纯白色,白色将是高光区域内的颜色
void CVirtualCylinder::SetColor(BYTE byRed, BYTE byGreen, BYTE byBlue)
{
	m_byRed = byRed;
	m_byGreen = byGreen;
	m_byBlue = byBlue;
}

//绘制
//(x,y)-----------------左上角坐标
//nWidth, nHeight-------宽度和高度
void CVirtualCylinder::Draw(CDC* pDC, int x, int y , int nWidth, int nHeight)
{
	if(nWidth < 1) return;

	//颜色
	float fRed = m_byRed;
	float fGreen = m_byGreen;
	float fBlue = m_byBlue;

	//颜色增量
	float fIncR = (2.0f * (255 - m_byRed)) / nWidth;
	float fIncG = (2.0f * (255 - m_byGreen)) / nWidth;
	float fIncB = (2.0f * (255 - m_byBlue)) / nWidth;

	for(int i = 0; i < (nWidth / 2); i++)
	{
		CPen pen(PS_SOLID, 1, RGB((BYTE)fRed, (BYTE)fGreen, (BYTE)fBlue));
		CPen* pOldPen = pDC->SelectObject(&pen);

		pDC->MoveTo(x + i, y);
		pDC->LineTo(x + i, y + nHeight);
		pDC->MoveTo(x + nWidth - i - 1, y);
		pDC->LineTo(x + nWidth - i - 1, y + nHeight);
		
		fRed += fIncR;
		fGreen += fIncG;
		fBlue += fIncB;

		pDC->SelectObject(pOldPen);
		pen.DeleteObject();
	}

	CPen pen(PS_SOLID, 1, RGB(255, 255, 255));
	CPen* pOldPen = pDC->SelectObject(&pen);

	pDC->MoveTo(x + i, y);
	pDC->LineTo(x + i, y + nHeight);
	
	pDC->SelectObject(pOldPen);
	pen.DeleteObject();
}

⌨️ 快捷键说明

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