CColor类封装

  1. Color.h

  

#pragma once

#include <sstream>
#include <string>
using namespace std; class CColor
{
public:
CColor(void);
~CColor(void); CColor(const CColor& color);
CColor& operator=(const CColor& color); CColor(float, float, float);
CColor(int, int, int);
CColor(COLORREF clr); // 以两个逗号分隔的字符串
CColor(const string& strColor); public:
COLORREF GetRGB();
DWORD GetARGB();
float GetR();
float GetG();
float GetB();
void SetStrValue(const string& strColor);
string GetStrValue();
string Trans2Txt(); private:
void ParseStrColor(const string& strColor); private:
byte m_tAlpha;
float m_fRed;
float m_fGreen;
float m_fBlue; };

  2. Color.cpp

  

#include "StdAfx.h"

#include "Color.h"

#include "Utils.h"

CColor::CColor(void) : m_tAlpha(255), m_fRed(.0f), m_fGreen(.0f), m_fBlue(.0f)
{
} CColor::~CColor(void)
{
} CColor::CColor( const CColor& color )
{
*this = color;
} CColor& CColor::operator=(const CColor& color )
{
if (this == &color)
{
return *this;
} m_tAlpha = color.m_tAlpha;
m_fRed = color.m_fRed;
m_fGreen = color.m_fGreen;
m_fBlue = color.m_fBlue; return *this;
} CColor::CColor( float fRed, float fGreen, float fBlue)
{
m_tAlpha = 255;
m_fRed = fRed;
m_fGreen = fGreen;
m_fBlue = fBlue;
} CColor::CColor( int nRed, int nGreen, int nBlue)
{
m_tAlpha = 255;
m_fRed = (float)nRed / 255;
m_fGreen = (float)nGreen / 255;
m_fBlue = (float)nBlue / 255;
} CColor::CColor( COLORREF clr )
{
byte* p = (byte*)&clr;
int nRed = *p++;
int nGreen = *p++;
int nBlue = *p++; m_tAlpha = 255;
m_fRed = (float)nRed / 255;
m_fGreen = (float)nGreen / 255;
m_fBlue = (float)nBlue / 255;
} COLORREF CColor::GetRGB()
{
COLORREF colorrrefRGB;
colorrrefRGB = RGB(byte(m_fRed * 255), byte(m_fGreen * 255), byte(m_fBlue * 255));
return colorrrefRGB;
} DWORD CColor::GetARGB()
{
byte tRed = byte(m_fRed * 255);
byte tGreen = byte(m_fGreen * 255);
byte tBlue = byte(m_fBlue * 255); return (((DWORD)(tBlue) << 0) |
((DWORD)(tGreen) << 8) |
((DWORD)(tRed) << 16) |
((DWORD)(m_tAlpha) << 24));
} float CColor::GetR()
{
return m_fRed;
} float CColor::GetG()
{
return m_fGreen;
} float CColor::GetB()
{
return m_fBlue;
} /**
* @brief 解析颜色字符串
*
* 根据指定字符串解析出颜色的三个分量
* 字符串以逗号或空格分割,如"strR,strG,strB" 其中strR,strG和strB都在0.0到1.0间取值
* @param[in] const string& strColor
* @return void
*/
void CColor::SetStrValue( const string& strColor )
{
ParseStrColor(strColor);
} std::string CColor::GetStrValue()
{
stringstream ss;
ss << Float2Str(m_fRed) << ", ";
ss << Float2Str(m_fGreen) << ", ";
ss << Float2Str(m_fBlue); return ss.str();
} std::string CColor::Trans2Txt()
{
return GetStrValue();
} void CColor::ParseStrColor( const string& strColor )
{
string strTmpValue = strColor;
TrimLineSpace(strTmpValue); string strSplitSymbol = ",";
size_t nSplitPos = strTmpValue.find_first_of(strSplitSymbol); if (nSplitPos == string::npos)
{
strSplitSymbol = " ";
} size_t nFirstPos = strTmpValue.find_first_of(strSplitSymbol); if (nFirstPos != string::npos)
{
string strValue = strTmpValue.substr(0, nFirstPos);
m_fRed = Str2Float(strValue); strTmpValue = strTmpValue.substr(nFirstPos + 1, string::npos);
TrimLineSpace(strTmpValue); nFirstPos = strTmpValue.find_first_of(strSplitSymbol); if (nFirstPos != string::npos)
{
strValue = strTmpValue.substr(0, nFirstPos);
m_fGreen = Str2Float(strValue);
} strTmpValue = strTmpValue.substr(nFirstPos + 1, string::npos);
TrimLineSpace(strTmpValue); if (strTmpValue != "")
{
m_fBlue = Str2Float(strTmpValue);
}
} m_tAlpha = 255;
}

CColor类封装的更多相关文章

  1. salesforce 零基础学习(四十八)自定义列表分页之Pagination基类封装 ※※※

    我们知道,salesforce中系统标准列表页面提供了相应的分页功能,如果要使用其分页功能,可以访问http://www.cnblogs.com/zero-zyq/p/5343287.html查看相关 ...

  2. Redis操作Set工具类封装,Java Redis Set命令封装

    Redis操作Set工具类封装,Java Redis Set命令封装 >>>>>>>>>>>>>>>>& ...

  3. Redis操作List工具类封装,Java Redis List命令封装

    Redis操作List工具类封装,Java Redis List命令封装 >>>>>>>>>>>>>>>> ...

  4. Redis操作Hash工具类封装,Redis工具类封装

    Redis操作Hash工具类封装,Redis工具类封装 >>>>>>>>>>>>>>>>>> ...

  5. Redis操作字符串工具类封装,Redis工具类封装

    Redis操作字符串工具类封装,Redis工具类封装 >>>>>>>>>>>>>>>>>>& ...

  6. java中基于TaskEngine类封装实现定时任务

    主要包括如下几个类: 文章标题:java中基于TaskEngine类封装实现定时任务 文章地址: http://blog.csdn.net/5iasp/article/details/10950529 ...

  7. C++基础——类封装简单示例

    一.前言 在IC前端设计/验证领域,只会HDL远远不够.目前大多数项目使用已开发好的系统架构和IP Core,因此设计部分的工作量慢慢向系统集成和验证方向转移.而在集成和验证过程中,往往以各种脚本和面 ...

  8. Timber(对Log类封装的一个工具)

    Timber(对Log类封装的一个工具) https://blog.csdn.net/hzl9966/article/details/51314137 https://www.jianshu.com/ ...

  9. Java中使用自定义类封装数组,添加类方法实现数据操作

    1.具体见注释 2.后续或有更新 public class MyArray { private long[] array; private int cnt; // 自定义数组类的元素个数 /** 使用 ...

随机推荐

  1. GUI—ST_emWin移植

    GUI-ST_emWin移植 一.st_emwin移植 1.stemwin源文件下载:ST官网 https://my.st.com/content/my_st_com/en/search.html#q ...

  2. iOS libyuv

    libyuv是Google开源库,可用作图像数据格式的转换,比如视频流编解码时格式的转换,YUV数据转化RGB等 libyuv静态库 为了方便使用,已经将libyuv源代码打包成了iOS静态库,lib ...

  3. 关于Tsung脚本无法停止的问题

    最近,利用tsung测试cm的时候,脚本是这样配置的: <load> 28 <arrivalphase phase="1" duration="2&qu ...

  4. MyEclipse2015上传项目到GitHub(很详细)

    MyEclipse 2015 默认已经安装了git插件,在MyEclipse中上传项目到github的步骤如下: 1.github官网(https://github.com)申请开通账号(略) 1.1 ...

  5. ajax 处理请求回来的数据

    比如接口 /test, 请求方式get, 请求过来的数据要处理在container 里,如下代码 $.get("/test", {}, function(result){ $(&q ...

  6. IdentityServer Topics(2)- 定义资源

    您通常在系统设计中的第一件事就是您要保护的资源. 这可能是您的用户的身份信息,如个人资料数据或电子邮件地址,或访问API. 您可以使用C#对象模型定义资源(硬编码),或从数据存储中加载它们. IRes ...

  7. Zabbix实战-简易教程--动作(Actions)--自动注册

    一.概述 之前已经讲述了自动发现功能,自动注册和自动发现非常类似,但是比自动发现更精确.因为自动注册,是在Agent上自定义元数据,然后Agent将元数据发送给server进行匹配,如果匹配一致,则进 ...

  8. 从头开始基于Maven搭建SpringMVC+Mybatis项目(3)

    接上文内容,本节介绍基于Mybatis的查询和分页功能,并展示一个自定义的分页标签,可重复使用以简化JSP页面的开发. 从头阅读传送门 在上一节中,我们已经使用Maven搭建好了项目的基础结构,包括一 ...

  9. BZOJ:4031: [HEOI2015]小Z的房间

    Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1103  Solved: 536[Submit][Status][Discuss] Descripti ...

  10. HDU 1711 Number Sequence(KMP裸题,板子题,有坑点)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...