最近做图片高亮处理,网上找了点资料,自己整理了下
方法1:
Gdiplus:: ColorMatrix HotMat =
{1.05f, 0.00f, 0.00f, 0.00f,0.00f,
0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.05f, 0.05f, 0.05f, 0.00f, 1.00f};
Gdiplus:: ImageAttributes imageAttr;
imageAttr.SetColorMatrix(&HotMat);
Gdiplus:: RectF rcDrawRect;
rcDrawRect.X=0;
rcDrawRect.Y=0;
rcDrawRect.Width=100;
rcDrawRect.Height=100;
HDC hdc=GetDC(m_HWND);
Gdiplus::Graphics graphics(hdc);
graphics.DrawImage(m_RowImage,rcDrawRect,0,0,1,m_ColumnHeight,Gdiplus:: UnitPixel,&imageAttr);
ReleaseDC(m_HWND,hdc);
方法2 SetGamma
Gdiplus:: ImageAttributes imageAttr;
imageAttr.SetGamma( 1/2.2f );
Gdiplus:: RectF rcDrawRect;
rcDrawRect.X=0;rcDrawRect.Y=0;
rcDrawRect.Width=100;
rcDrawRect.Height=100;
HDC hdc=GetDC(m_HWND);
Gdiplus::Graphics graphics(hdc);
graphics.DrawImage(m_RowImage,rcDrawRect,0,0,1,m_ColumnHeight,Gdiplus:: UnitPixel,&imageAttr);
ReleaseDC(m_HWND,hdc);
本文链接
最近做图片高亮处理,网上找了点资料,自己整理了下
方法1:
Gdiplus:: ColorMatrix HotMat =
{1.05f, 0.00f, 0.00f, 0.00f,0.00f,
0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.05f, 0.05f, 0.05f, 0.00f, 1.00f};
Gdiplus:: ImageAttributes imageAttr;
imageAttr.SetColorMatrix(&HotMat);
Gdiplus:: RectF rcDrawRect;
rcDrawRect.X=0;
rcDrawRect.Y=0;
rcDrawRect.Width=100;
rcDrawRect.Height=100;
HDC hdc=GetDC(m_HWND);
Gdiplus::Graphics graphics(hdc);
graphics.DrawImage(m_RowImage,rcDrawRect,0,0,1,m_ColumnHeight,Gdiplus:: UnitPixel,&imageAttr);
ReleaseDC(m_HWND,hdc);
方法2 SetGamma
Gdiplus:: ImageAttributes imageAttr;
imageAttr.SetGamma( 1/2.2f );
Gdiplus:: RectF rcDrawRect;
rcDrawRect.X=0;rcDrawRect.Y=0;
rcDrawRect.Width=100;
rcDrawRect.Height=100;
HDC hdc=GetDC(m_HWND);
Gdiplus::Graphics graphics(hdc);
graphics.DrawImage(m_RowImage,rcDrawRect,0,0,1,m_ColumnHeight,Gdiplus:: UnitPixel,&imageAttr);
ReleaseDC(m_HWND,hdc);
本文链接
事件模型是被广泛使用的好东西,但是C++标准库里没有现成的,其他实现又复杂或者不优雅,比如需要使用宏。现在VC11可以用在XP下了,那么就痛快的拿起C++11提供的先进设施组合出一个轻便的实现吧。
为了达到简洁的目的,需要放弃一些特性:
1、不支持判断函数是否已经绑定过(因为std::function不提供比较方法,自己实现function的话代码又变多了)
2、需要使用者接收返回的回调函数标识来移除事件绑定(原因同上)
3、事件没有返回值,不支持回调函数优先级、条件回调等事件高级特性(比如返回所有处理结果中的最大最小值;只回调与指定参数匹配的事件处理函数)
4、事件参数理论上无限,实际上有限,一般支持0~10个参数(VC11还没有支持变长模板参数,GCC有了。不过可以通过缺省模板参数和偏特化来模拟,所以理论上无限制)
5、不是线程安全的
注:3、5两条可以通过引入策略模式来提供灵活支持,就像标准库和Loki做的那样,实现一个完整的事件机制。
最简单的实现
2 #include <functional>
3
4 using namespace std;
5
6
7 template<class Param1, class Param2>
8 class Event
9 {
10 typedef void HandlerT(Param1, Param2);
11 int m_handlerId;
12
13 public:
14 Event() : m_handlerId(0) {}
15
16 template<class FuncT> int addHandler(FuncT func)
17 {
18 m_handlers.emplace(m_handlerId, forward<FuncT>(func));
19 return m_handlerId++;
20 }
21
22 void removeHandler(int handlerId)
23 {
24 m_handlers.erase(handlerId);
25 }
26
27 void operator ()(Param1 arg1, Param2 arg2)
28 {
29 for ( const auto& i : m_handlers )
30 i.second(arg1, arg2);
31 }
32
33 private:
34 map<int, function<HandlerT>> m_handlers;
35 };
addHandler把回调函数完美转发给std::function,让标准库来搞定各种重载,然后返回一个标识符用来注销绑定。试一下,工作的不错:
2 {
3 puts("f1()");
4 }
5
6 struct F2
7 {
8 void f(int, int)
9 {
10 puts("f2()");
11 }
12
13 void operator ()(int, int)
14 {
15 puts("f3()");
16 }
17 };
18
19 int _tmain(int argc, _TCHAR* argv[])
20 {
21 Event<int, int> e;
22
23 int id = e.addHandler(f1);
24
25 e.removeHandler(id);
26
27 using namespace std::placeholders;
28
29 F2 f2;
30
31 e.addHandler(bind(&F2::f, f2, _1, _2));
32 e.addHandler(bind(f2, _1, _2));
33
34 e.addHandler([](int, int) {
35 puts("