图像特效---挤压(Pinch)滤镜
来源:互联网 发布:c 二维数组动态赋值 编辑:程序博客网 时间:2024/04/28 12:55
Pinch滤镜
Pinch滤镜是通过坐标变换来实现以某个点(cenX,cenY)为中心,某个半径R内图像向其挤压变形的效果。实现这个滤镜的算法很多,主要是数学公式的不同,大家可以自行设计,这里给个代码示例,大家可以直接使用。
代码如下:
//
///
/// Pinch Filter
///
/// Source image.
/// The X position of sun.
/// The Y position of sun.
/// The result image.
private Bitmap PinchFilterProcess(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,degree = 10;
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));
radius = (int)(Math.Sqrt(radius) * degree);
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;
}
效果图如下:
原图
Pinch滤镜效果图
demo:http://www.zealfilter.com/forum.php?mod=viewthread&tid=55&extra=page%3D2
0 0
- 图像特效---挤压(Pinch)滤镜
- 图像滤镜艺术---挤压(Pinch)滤镜
- 图像特效之挤压特效
- 图像特效---漫画滤镜
- 图像特效---连环画滤镜
- 图像特效---马赛克滤镜
- 图像特效---Wave滤镜
- 图像特效---Swirl滤镜
- 图像特效---水彩画滤镜
- 图像特效---旋转模糊滤镜
- 图像特效---(Instagram)1977滤镜
- 图像特效---怀旧风格滤镜
- 图像特效---暗调滤镜
- 图像特效---Oilpaint油画滤镜
- 图像特效---哈哈镜效果滤镜
- 图像特效---球面(Spherize)滤镜
- 图像特效---(Sketch Filter)素描滤镜
- 图像特效---Glow Filter发光滤镜
- 最小编辑代价
- MVC简易购物车项目--展示购物车页面
- Scheme之功能分解和封装内部函数/块结构
- 数据成员的初始化
- SEL
- 图像特效---挤压(Pinch)滤镜
- Android之根据Uri获得图片或视频文件路径(解决4.4以上版本得不到路径的情况)
- HYSBZ - 1026 windy数 (数位DP)
- String的substring()的用法总结
- 图像特效---球面(Spherize)滤镜
- Linux中的线程局部存储(一)
- python删除安装的模块
- 关于JSON
- nyoj27 搜索