//图像反色处理
Color color,colorTemp;
int red,green,blue,x,y;
for(int x=0;x<image.GetWidth();x++)
{
for(int y=0;y<image.GetHeight();y++)
{
image.GetPixel(x,y,&color);
red = (int)(255-color.GetRed());
green =(int)(255-color.GetGreen());
blue = (int)(255-color.GetBlue());
image.SetPixel(x,y,colorTemp.MakeARGB(255,red,green,blue));
}
}
//图像锐化处理
for(int i=1;i<image->GetWidth()-1;i++)
{
for(int j=1;j<image->GetHeight()-1;j++)
{
image->GetPixel(i,j,&colornow);
image->GetPixel(i-1,j-1,&colorLeft);
float r=colornow.GetRed()+(colornow.GetRed()-colorLeft.GetRed()*dep);
r=min(255,max(0,r));
float g=colornow.GetGreen()+(colornow.GetGreen()-colorLeft.GetGreen()*dep);
g=min(255,max(0,g));
float b=colornow.GetBlue()+(colornow.GetBlue()-colorLeft.GetBlue()*dep);
b=min(255,max(0,b));
colorTemp.SetValue(color3.MakeARGB(255,r,g,b));
image->SetPixel(i,j,colorTemp);
}
}
break;
case 2:
//图像模糊处理
for(int i=1;i<image->GetWidth()-2;i++)
{
for(int j=1;j<image->GetHeight()-2;j++)
{
image->GetPixel(i-1,j-1,&color[0][0]);
image->GetPixel(i-1,j, &color[0][1]);
image->GetPixel(i-1,j+1,&color[0][2]);
image->GetPixel(i,j-1,&color[1][0]);
image->GetPixel(i,j, &color[1][1]);
image->GetPixel(i,j+1,&color[1][2]);
image->GetPixel(i+1,j-1,&color[2][0]);
image->GetPixel(i+1,j, &color[0][2]);
image->GetPixel(i+1,j+1,&color[2][2]);
int rSum=0;
int gSum=0;
int bSum=0;
//分别求出9个点的R、G、B之和
for(int n=0;n<3;n++)
for(int nn=0;nn<3;nn++)
{
rSum+=color[n][nn].GetRed();
gSum+=color[n][nn].GetGreen();
bSum+=color[n][nn].GetBlue();
}
colorTemp.SetValue(color2.MakeARGB(255,float(rSum/9),float(gSum/9),float(bSum/9)));
image->SetPixel(i,j,colorTemp);
}
}
break;
case 3:
//图像浮雕处理
for(int i=0;i<image->GetWidth();i++)
{
for(int j=0;j<image->GetHeight();j++)
{
image->GetPixel(i,j,&color4);
image->GetPixel(i+1,j+1,&colorLeft);//分量值之差被限制在67-128之间,更改这两个值会得到不同的效果
float r=max(67,min(255,abs(color4.GetRed()-colorLeft.GetRed()+128)));
float g=max(67,min(255,abs(color4.GetGreen()-colorLeft.GetGreen()+128)));
float b=max(67,min(255,abs(color4.GetBlue()-colorLeft.GetBlue()+128)));
colorTemp.SetValue(color4.MakeARGB(255,r,g,b));//将计算后的之写入到位图
image->SetPixel(i,j,colorTemp);
}
}
break;
}
GetDocument()->SetModifiedFlag();//保存修改确认
}
OnPicture();
//图像木刻处理
Color color,colorTemp;
int avg,temp;
for(int i=0;i<image->GetWidth();i++)
{
for(int j=0;j<image->GetHeight();j++)
{
image->GetPixel(i,j,&color);
avg=(color.GetRed()+color.GetGreen()+color.GetBlue())/3;
if(192>=avg)
{temp=255;}
else if(128<avg<192)
{temp=150;}
else if (64<=avg<=128)
{temp=150;}
else if (avg<64)
{temp=8;}
colorTemp.SetValue(color.MakeARGB(255,temp,temp,temp));
image->SetPixel(i,j,colorTemp);
}
}
//图像雕刻处理
Color color,colorTemp,colorLeft;
for(int i=image->GetWidth();i>0;i--)
{
for(int j=image->GetHeight();j>0;j--)
{
image->GetPixel(i,j,&color);
image->GetPixel(i-1,j-1,&colorLeft);//分量值之差被限制在67-128之间,更改这两个值会得到不同的效果
float r=max(67,min(255,abs(color.GetRed()-colorLeft.GetRed()+128)));
float g=max(67,min(255,abs(color.GetGreen()-colorLeft.GetGreen()+128)));
float b=max(67,min(255,abs(color.GetBlue()-colorLeft.GetBlue()+128)));
colorTemp.SetValue(color.MakeARGB(255,r,g,b));//将计算后的之写入到位图
image->SetPixel(i,j,colorTemp);
}
}
//水平百叶窗
int i,j;
for(int j=0;j<=image->GetHeight()/12;j++)
for(int i=0; i<=12;i++ )
{
pDC = GetDC();
ImageAttributes ImgAttr;
Graphics graphics(*pDC);
graphics.DrawImage(image, Rect(0,i*image->GetHeight()/12,image->GetWidth(),j),0,i*image->GetHeight()/12,image->GetWidth() , j,UnitPixel,&ImgAttr);
}
//垂直百叶窗
int i,j;
for(int i=0;i<=image->GetWidth()/10;i++)
for(int j=0; j<=10;j++ )
{
pDC = GetDC();
ImageAttributes ImgAttr;
Graphics graphics(*pDC);
graphics.DrawImage(image, Rect(j*image->GetWidth()/10,0,i,image->GetHeight()),j*image->GetWidth()/10, 0 , i,image->GetHeight(),UnitPixel,&ImgAttr);
}
//以上代码采用用GDI+绘图方法完美实现