图像特效---Swirl滤镜
来源:互联网 发布:什么软件看电影清楚 编辑:程序博客网 时间:2024/04/30 11:11
原图
效果图
代码如下:
//
///
/// Swirl Filter
///
/// Source image.
/// The X position of Swirl.
/// The Y position of Swirl.
/// The degree of swirl,0-360.
/// The result image.
private Bitmap SwirlFilterProcess(Bitmap srcBitmap, int cenX, int cenY, int swilDegree)
{
Bitmap a = new Bitmap(srcBitmap);
int w = a.Width;
int h = a.Height;
int radius = 0;
swilDegree = Math.Max(0, Math.Min(360, swilDegree));
double k = swilDegree / 3600.0;
Bitmap dst = new Bitmap(w, h);
System.Drawing.Imaging.BitmapData srcData = a.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Imaging.BitmapData dstData = dst.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
unsafe
{
byte* pIn = (byte*)srcData.Scan0.ToPointer();
byte* pOut = (byte*)dstData.Scan0.ToPointer();
byte* p = null;
int stride = srcData.Stride - w * 4;
int offsetX = 0, offsetY = 0;
int newX = 0, newY = 0;
double radian = 0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
offsetX = x - cenX;
offsetY = y - cenY;
radian = Math.Atan2(offsetY, offsetX);
radius = (int)(Math.Sqrt(offsetX * offsetX + offsetY * offsetY));
newX = (int)(radius * Math.Cos(radian + k * radius)) + cenX;
newY = (int)(radius * Math.Sin(radian + k * radius)) + cenY;
newX = Math.Min(w - 1, Math.Max(0, newX));
newY = Math.Min(h - 1, Math.Max(0, newY));
p = pIn + newY * srcData.Stride + 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;
}
a.UnlockBits(srcData);
dst.UnlockBits(dstData);
}
return dst;
}
程序demo: http://www.zealfilter.com/forum.php?mod=viewthread&tid=58&extra=page%3D1
- 图像特效---Swirl滤镜
- 图像滤镜艺术---Swirl滤镜
- 图像特效---漫画滤镜
- 图像特效---连环画滤镜
- 图像特效---马赛克滤镜
- 图像特效---Wave滤镜
- 图像特效---水彩画滤镜
- 图像特效---旋转模糊滤镜
- 图像特效---(Instagram)1977滤镜
- 图像特效---怀旧风格滤镜
- 图像特效---暗调滤镜
- 图像特效---Oilpaint油画滤镜
- 图像特效---哈哈镜效果滤镜
- 图像特效---挤压(Pinch)滤镜
- 图像特效---球面(Spherize)滤镜
- 图像特效---(Sketch Filter)素描滤镜
- 图像特效---Glow Filter发光滤镜
- 图像特效---(Lightleaks Filter)漏光滤镜
- python with用法
- 剑指offer之面试题8旋转数组的最小数字
- 设计模式23篇:中介者模式
- Material Design使用总结
- linux设备模型之内核对象kobject
- 图像特效---Swirl滤镜
- jquery实现tab栏
- 拆解轮子之XRecyclerView
- ajax 同步
- Ubuntu 12.04 系统安装
- 图像特效---水彩画滤镜
- Linux中的线程局部存储(二)
- Ubuntu 13.04 系统安装
- linux基本命令(20)——find命令之exec