1.用快速读写进行颜色转变
#include<iostream>
#include<atlimage.h>
using namespace std;
int main()
{
const char *srcFilePath = "21a.jpg", *destFilePath = "21b.jpg";
CImage srcImage;
srcImage.Load(srcFilePath);
int width = srcImage.GetWidth(), height = srcImage.GetHeight();
int bpp = srcImage.GetBPP(), pitch = srcImage.GetPitch();
BYTE *pData = (BYTE *)srcImage.GetBits();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
BYTE b = *(pData + pitch * y + x * bpp / 8 + 0);
BYTE g = *(pData + pitch * y + x * bpp / 8 + 1);
BYTE r = *(pData + pitch * y + x * bpp / 8 + 2);
*(pData + pitch * y + x * bpp / 8 + 0) = r;
*(pData + pitch * y + x * bpp / 8 + 1) = g;
*(pData + pitch * y + x * bpp / 8 + 2) = b;
}
}
srcImage.Save(destFilePath);
return 0;
}
2.用快速读写改变颜色灰度值
#include<iostream>
#include<atlimage.h>
using namespace std;
int main()
{
const char *srcFilePath = "22a.jpg", *destFilePath = "22b.jpg";
CImage srcImage;
srcImage.Load(srcFilePath);
int width = srcImage.GetWidth(), height = srcImage.GetHeight();
int