#include <graphics.h>
#include <conio.h>
int abs(int a)
{
if(a<0)a*=-1;
return a;
}
//排除颜色avoid_color,容差为deviation
void my_putimg(int dstX,int dstY,IMAGE *pimg,int avoid_color,int deviation)
{
intwidth= pimg->width;// 图像的宽
intheight= pimg->height;// 图像的高
int x,y,color,num;
int avoid_r=GetRValue(avoid_color);
int avoid_g=GetGValue(avoid_color);
int avoid_b=GetBValue(avoid_color);
IMAGE pSrcImg;//背景图
SetWorkingImage(NULL);//对默认绘图窗口的绘图操作
getimage(&pSrcImg,dstX,dstY,width,height);
// 获取背景指向显存的指针
DWORD* bk_pMem = GetImageBuffer(&pSrcImg);
//获取贴图指向显存的指针
DWORD* pMem = GetImageBuffer(pimg);
for(y=0;y<height;y++)
{
for(x=0;x<width;x++)
{
num = y*width+x;
color = pMem[num];
if(abs(GetRValue(color)-avoid_r) < deviation)
{
if(abs(GetGValue(color)-avoid_g) < deviation)
{
if(abs(GetBValue(color)-avoid_b) < deviation)
pMem[num] = bk_pMem[num];
}
}
}
}
putimage(dstX, dstY, pimg);
}
int main()
{
IMAGE bk_img,front_img;
initgraph(640, 480);
loadimage(&bk_img,".\\img\\bk.jpg",0,0,false);
loadimage(&front_img,".\\img\\front.jpg",0,0,false);
putimage(0,0,&bk_img);
my_putimg(200,0,&front_img,0xff00fe,40);
getch();
EndBatchDraw();
return 0;
}