图像特效---挤压(Pinch)滤镜
Pinch滤镜
Pinch滤镜是通过坐标变换来实现以某个点(cenX,cenY)为中⼼,某个半径R内图像向其挤压变形的效果。实现这个滤镜的算法很多,主要是数学公式的不同,⼤
家可以⾃⾏设计,这⾥给个代码⽰例,⼤家可以直接使⽤。
代码如下:
//
///
///PinchFilter
///
///Sourceimage.
///TheXpositionofsun.
///TheYpositionofsun.
///Theresultimage.
privateBitmapPinchFilterProcess(BitmapsrcBitmap,intcenX,intcenY)
{
Bitmapa=newBitmap(srcBitmap);
intw=;
inth=;
intradius=0;
Bitmapdst=newBitmap(w,h);
DatasrcData=ts(newRectangle(0,0,w,h),ite,
32bppArgb);
DatadstData=ts(newRectangle(0,0,w,h),ite,
32bppArgb);
unsafe
{
byte*pIn=(byte*)ter();
byte*pOut=(byte*)ter();
byte*p=null;
intsWidth=;
intstride=sWidth-w*4;
intofftX=0,offtY=0;
intnewX=0,newY=0;
doubleradian=0,degree=10;
for(inty=0;y
{
for(intx=0;x
{
offtX=x-cenX;
offtY=y-cenY;
radian=2(offtY,offtX);
radius=(int)((offtX*offtX+offtY*offtY));
radius=(int)((radius)*degree);
newX=(int)(radius*(radian))+cenX;
newY=(int)(radius*(radian))+cenY;
newX=(w-1,(0,newX));
newY=(h-1,(0,newY));
p=pIn+newY*+newX*4;
pOut[0]=(byte)p[0];
pOut[1]=(byte)p[1];
pOut[2]=(byte)p[2];
pOut[3]=(byte)255;
pOut+=4;
}
pOut+=stride;
}
Bits(srcData);
Bits(dstData);
}
returndst;
}
效果图如下:
原图
Pinch滤镜效果图
本文发布于:2022-11-12 10:48:41,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/88/4082.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |