CImage类进行图像处理1(基础篇)

1.实现红色部分变蓝

#include<iostream>

#include<atlimage.h>

using namespace std;

void swapRGWhenGedMax(COLORREF &c)

{

int r = GetRValue(c);

int g = GetGValue(c);

int b = GetBValue(c);

if (r > g && r > b)

{

swap(r, b);

}

c = RGB(r, g, b);

}

int main()

{

const char *srcFilePath = "1a.jpg";

const char *destFilePath = "1b.jpg";

CImage srclmage;

srclmage.Load(srcFilePath);

int width = srclmage.GetWidth();

int height = srclmage.GetHeight();

for (int x = 0; x < width; x++)

{

for (int y = 0; y < height; y++)

{

COLORREF c = srclmage.GetPixel(x, y);

swapRGWhenGedMax(c);

srclmage.SetPixel(x, y, c);

}

}

srclmage.Save(destFilePath);

return 0;

 

}

 

 

2.实现图片反色

#include<iostream>

#include<atlimage.h>

using namespace std;

void swapRGWhenGedMax(COLORREF &c)

{

int r = GetRValue(c);

int g = GetGValue(c);

int b = GetBValue(c);

c = RGB(255 - r, 255 - g, 255 - b);

}

int main()

{

const char *srcFilePath = "2a.jpg";

const char *destFilePath = "2b.jpg";

CImage srclmage;

srclmage.Load(srcFilePath);

int width = srclmage.GetWidth();

int height = srclmage.GetHeight();

for (int x = 0; x < width; x++)

{

for (int y = 0; y < height; y++)

{

COLORREF c = srclmage.GetPixel(x, y);

swapRGWhenGedMax(c);

srclmage.SetPixel(x, y, c);

}

}

srclmage.Save(destFilePath);

return 0;

 

}

 

 

 

 

3.提取

#include<iostream>

#include<atlimage.h>

using namespace std;

void swapRGWhenGedMax(COLORREF &c)

{

int r = GetRValue(c);

int g = GetGValue(c);

int b = GetBValue(c);

 

if (70 < r && r< 99 && b < 30) //防止后期洞的出现,将r调到大于99

{

r = 103;

g = 29;

b = 4;

}

if (r < 99)

{

r = 255;

g = 255;

b = 255;

}

 

c = RGB(r, g, b);

}

int main()

{

const char *srcFilePath = "3a.jpg";

const char *destFilePath = "3b3.jpg";

CImage srclmage;

srclmage.Load(srcFilePath);

int width = srclmage.GetWidth();

int height = srclmage.GetHeight();

for (int x = 0; x < width; x++)

{

for (int y = 0; y < height; y++)

{

COLORREF c = srclmage.GetPixel(x, y);

swapRGWhenGedMax(c);

srclmage.SetPixel(x, y, c);

}

}

srclmage.Save(destFilePath);

return 0;

 

}

猜你喜欢

转载自blog.csdn.net/a66666_/article/details/81224983
今日推荐