图像滤镜艺术---球面(Spherize)滤镜
来源:互联网 发布:淘宝生活服务市场清退 编辑:程序博客网 时间:2024/05/22 01:31
球面(Spherize)滤镜
球面滤镜是通过极坐标变换实现图像的球面特效。
代码如下:
//
///
/// /// 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
0 0
- 图像滤镜艺术---球面(Spherize)滤镜
- 图像特效---球面(Spherize)滤镜
- PS 滤镜——(扭曲)球面化 Spherize
- 图像滤镜艺术----Brannan滤镜
- 图像滤镜艺术--Toaster滤镜
- 图像滤镜艺术--暴雨滤镜
- 图像滤镜艺术--大雪滤镜
- 图像滤镜艺术---连环画滤镜
- 图像滤镜艺术---漫画滤镜
- 图像滤镜艺术---水彩画滤镜
- 图像滤镜艺术---Swirl滤镜
- 图像滤镜艺术---Wave滤镜
- 图像滤镜艺术----Brannan滤镜
- 图像滤镜艺术--序言
- 图像滤镜艺术---图像光照效果滤镜
- 图像滤镜艺术---Hudson滤镜(Instagram)
- 图像滤镜艺术--大雾效果滤镜
- 图像滤镜艺术---暗调滤镜
- ip介绍
- linux下weblogic 12c 之集群技术
- Android Studio更新升级方法
- C++Primer第五版 6.6节练习
- Oracle Sql相关记录
- 图像滤镜艺术---球面(Spherize)滤镜
- linux入门教程
- 微信接口封装
- scala学习笔记(六)包与引入
- urho3D编译文档工程出现的BUG
- Servlet Get方式请求数据 中文乱码 转码
- Yii权限管理工具Srbac使用小结
- 单词接龙
- Linux学习笔记-----虚拟机的三种网卡模式