#include "stdafx.h"
#include <algorithm>
#include "GDIPlusEx.h"
//************************************************---------------------------
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
CGDIPlus::CGDIPlus()
{
gdiplusToken=0;
//GDI+初始化
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
}
CGDIPlus::~CGDIPlus()
{
//GDI+关闭
if (0 != gdiplusToken)
{
GdiplusShutdown(gdiplusToken);
}
}
/////////////////////////////////////////////////
//函数名:ChangeColor
//功 能:转换Graphics::Color的值为Gdiplus::Color的值
//参 数:aColor 被转换颜色值
//返 回:Gdiplus::Color(Gdiplus类型颜色值)
//说 明:转换颜色
/////////////////////////////////////////////////
Gdiplus::Color ChangeColor(COLORREF aColor)
{
int liRed,liGreen,liBlue;
liRed = GetRValue(aColor);
liGreen = GetGValue(aColor);
liBlue = GetBValue(aColor);
return Color(liRed,liGreen,liBlue);
}
/////////////////////////////////////////////////
//函数名:ucFillRectangle
//功 能:填充矩形区域
//参 数:DC (HDC) 绘图设备
// aRect (RECT) 绘制矩形区域
// aColor (COLORREF) 填充颜色
// abEclosion (BOOL) 是否羽化
//返 回:NULL
//说 明:单色填充矩形区域
/////////////////////////////////////////////////
void CGDIPlus::usFillRectangle(HDC DC, RECT aRect, COLORREF aColor, BOOL abEclosion)
{
Graphics usGraphics(DC);
Color lgColor = ChangeColor(aColor);
if (abEclosion)
usGraphics.SetSmoothingMode(SmoothingModeHighQuality); //低速、高质量
SolidBrush lpBrush(lgColor);
usGraphics.FillRectangle(&lpBrush, aRect.left, aRect.top, aRect.right - aRect.left, aRect.bottom - aRect.top);
}
/////////////////////////////////////////////////
//函数名:usFillRectangle
//功 能:填充矩形区域
//参 数:DC (HDC) 绘图设备
// aRect (RECT) 绘制矩形区域
// aBeginColor (COLORREF) 起始颜色
// aEndColor (COLORREF) 结束颜色
// aBeginPoint (POINT) 画刷起始点
// aEndPoint (POINT) 画刷结束点
// abEclosion (BOOL) 是否羽化
//返 回:NULL
//说 明:渐变色填充矩形区域
/////////////////////////////////////////////////
void CGDIPlus::usFillRectangle(HDC DC, RECT aRect, COLORREF aBeginColor, COLORREF aEndColor, POINT aBeginPoint, POINT aEndPoint, BOOL abEclosion)
{
Graphics usGraphics(DC);
Color lBeginColor = ChangeColor(aBeginColor) ;
Color lEndColor = ChangeColor(aEndColor) ;
if (abEclosion)
{
usGraphics.SetSmoothingMode(SmoothingModeHighQuality); //低速、高质量
}
LinearGradientBrush linGrBrush(
Point(aBeginPoint.x, aBeginPoint.y),
Point(aEndPoint.x, aEndPoint.y),
lBeginColor,
lEndColor);
usGraphics.FillRectangle(&linGrBrush, aRect.left, aRect.top, aRect.right - aRect.left, aRect.bottom - aRect.top);
}
/////////////////////////////////////////////////
//函数名:usFillRectangle
//功 能:填充矩形区域
//参 数:DC (HDC) 绘图设备
// aRect (RECT) 绘制矩形区域
// aBeginColor (COLORREF) 渐变开始颜色
// aEndColor (COLORREF) 渐变结束颜色
// Orientation (ENUM_DrawOrientation) 渐变方向
// abEclosion(BOOL) 是否羽化
//返 回:NULL
//说 明:填充矩形区域,可选择渐变方式及渐变方向,以及亮度校正
/////////////////////////////////////////////////
void CGDIPlus::usFillRectangle(HDC DC, RECT aRect, COLORREF aBeginColor, COLORREF aEndColor, ENUM_DrawOrientation Orientation, BOOL abEclosion)
{
Graphics usGraphics(DC);
Color lgBeginColor = ChangeColor(aBeginColor);
Color lgEndColor = ChangeColor(aEndColor) ;
if (abEclosion)
{
usGraphics.SetSmoothingMode(SmoothingModeHighQuality); //低速、高质量
}
if (Orientation == edoVertical)
{
LinearGradientBrush linGrBrush(
Point(aRect.left, aRect.top - 1),
Point(aRect.left, aRect.bottom),
lgBeginColor,
lgEndColor);
linGrBrush.SetGammaCorrection(TRUE);
usGraphics.FillRectangle(&linGrBrush, aRect.left, aRect.top, aRect.right - aRect.left, aRect.bottom - aRect.top);
}
else
{
LinearGradientBrush linGrBrush(
Point(aRect.left - 1, aRect.top),
Point(aRect.right, aRect.top),
lgBeginColor,
lgEndColor);
linGrBrush.SetGammaCorrection(TRUE);
usGraphics.FillRectangle(&linGrBrush, aRect.left, aRect.top, aRect.right - aRect.left, aRect.bottom - aRect.top);
}
}
/////////////////////////////////////////////////
//函数名:usFillRectangle
//功 能:填充矩形
//参 数:DC (HDC) 绘图设备
// aRect (RECT) 填充区域
// aColor (COLORREF) 背景色
// aAlpha (INT) 背景色透明度(0~255)
// abEclosion (BOOL) 是否支持羽化
//返 回:NULL
//说 明:填充矩形时可带颜色透明参数
/////////////////////////////////////////////////
void CGDIPlus::usFillRectangle(HDC DC, RECT aRect, COLORREF aColor, INT aAlpha, BOOL abEclosion)
{
Graphics usGraphics(DC);
INT liRed, liGreen, liBlue;
liRed = GetRValue(aColor);
liGreen = GetGValue(aColor);
liBlue = GetBValue(aColor);
Color lgColor(aAlpha, liRed, liGreen, liBlue);
if (abEclosion)
usGraphics.SetSmoothingMode(SmoothingModeHighQuality); //低速、高质量
SolidBrush lpBrush(lgColor);
usGraphics.FillRectangle(&lpBrush, aRect.left, aRect.top, aRect.right - aRect.left, aRect.bottom - aRect.top);
}
/////////////////////////////////////////////////
//函数名:usFillCenterRectangle
//功 能:填充矩形区域
//参 数:DC (HDC) 绘图设备
// aRect (RECT) 绘制矩形区域
// aCenterColor (COLORREF) 渐变中间颜色
// aSurroundColor (COLORREF) 渐变周围颜色
// afCenterWidth (FLOAT) 中间渐变方式宽度向量调整
// afCenterHeight (FLOAT) 中间渐变方式高度向量调整
// abEclosion(BOOL) 是否羽化
//返 回:NULL
//说 明:填充矩形区域,可选择从两边向中间渐变的方式
/////////////////////////////////////////////////
void CGDIPlus::usFillCenterRectangle(HDC DC, RECT aRect, COLORREF aCenterColor, COLORREF aSurroundColor, FLOAT afCenterWidth, FLOAT afCenterHeight, BOOL abEclosion)
{
Graphics usGraphics(DC);
GraphicsPath lpPath;
lpPath.AddRectangle(Rect(aRect.left, aRect.top, aRect.right - aRect.left, aRect.bottom - aRect.top));
PathGradientBrush pthGrBrush(&lpPath);
pthGrBrush.SetGammaCorrection(TRUE);
Color lSurroundColor = ChangeColor(aSurroundColor);
Color lCenterColor = ChangeColor(aCenterColor);
INT num = 1;
pthGrBrush.SetSurroundColors(&lSurroundColor, &num);
pthGrBrush.SetCenterColor(lCenterColor);
if (abEclosion)
{
usGraphics.SetSmoothingMode(SmoothingModeHighQuality); //低速、高质量
}
pthGrBrush.SetFocusScales(afCenterWidth, afCenterHeight);
usGraphics.FillPath(&pthGrBrush, &lpPath);
}
/////////////////////////////////////////////////
//函数名:usFillRound
//功 能:填充矩形内切圆
//参 数:DC (HDC) 绘图设备
// aRect (RECT) 绘制矩形区域
// aColor (COLORREF) 填充颜色
// abEclosion (BOOL) 是否羽化
//返 回:NULL
//说 明:填充单色矩形内切圆
/////////////////////////////////////////////////
void CGDIPlus::usFillRound(HDC DC, RECT aRect, COLORREF aColor, BOOL abEclosion)
{
Graphics usGraphics(DC);
Color lgColor = ChangeColor(aColor) ;
if (abEclosion)
{
usGraphics.SetSmoothingMode(SmoothingModeHighQuality); //低速、高质量
}
SolidBrush lpBrush(lgColor);
usGraphics.FillEllipse(&lpBrush, aRect.left, aRect.top, aRect.right - aRect.left, aRect.bottom - aRect.top);
}
/////////////////////////////////////////////////
//函数名:usFillRound
//功 能:填充矩形内切圆
//参 数:DC (HDC) 绘图设备
// aRect (RECT) 绘制矩形区域
// aBeginColor (COLORREF) 渐变开始颜色
// aEndColor (COLORREF) 渐变结束颜色
// Orientation (ENUM_DrawOrientation) 渐变方向
// abEclosion (BOOL) 是否羽化
//返 回:NULL
//说 明:填充矩形内切圆,可选择渐变方式及渐变方向,以及亮度校正
/////////////////////////////////////////////////
void CGDIPlus::usFillRound(HDC DC, RECT aRect, COLORREF aBeginColor, COLORREF aEndColor, ENUM_DrawOrientation Orientation, BOOL abEclosion)
{
Graphics u
评论1
最新资源