图像滤镜艺术---球面(Spherize)滤镜
2015-09-15 11:06
344 查看
球面(Spherize)滤镜 球面滤镜是通过极坐标变换实现图像的球面特效。 代码如下: // /// /// Pinch Filter /// /// Source image. /// The X position of sun. /// The Y position of sun. /// The result image. private Bitmap SpherizeFilterProcess(Bitmap srcBitmap, int cenX, int cenY) { Bitmap a = new Bitmap(srcBitmap); int w = a.Width; int h = a.Height; int radius = 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 sWidth = srcData.Stride; int stride = sWidth - 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)((offsetX * offsetX + offsetY * offsetY) / Math.Max(cenX, cenY)); newX = (int)(radius * Math.Cos(radian)) + cenX; newY = (int)(radius * Math.Sin(radian)) + 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; } 效果图如下: 原图 效果图(X=240,Y=240) 最后放上一个完整的C#板程序DEMO:http://www.zealpixel.com/forum.php?mod=viewthread&tid=56&extra=page%3D1 |
相关文章推荐
- VirtualBox: Effective UID is not root (euid=1000 egid=100 uid=1000 gid=100)
- Android --账户注销
- Blog CSS
- scala学习笔记(五) 类
- android中wifi的上下层的连接、命令发送
- 欢迎使用CSDN-markdown编辑器
- 新浪博客发表博文不同步到新浪微博
- 排序
- 图像滤镜艺术---Wave滤镜
- js中的排序
- 百度地图 开始时的一个误区
- new operator,operator new,placement new
- 让Windows下的Tomcat将控制台信息记录到日志
- CSS3 媒体查询
- [iOS实战进阶]iOS开发完毕,提测时如何发包
- 图像滤镜艺术---Swirl滤镜
- unity5在小米2/2s等小米机器上闪退
- 优先级搜索
- C++微专业课程辅导(内存模型和动态内存)
- overflow清楚浮动 + 去掉li标签的小圆点