滤镜之变形Distort特效
来源:互联网 发布:淘宝宝贝拍照要求 编辑:程序博客网 时间:2024/05/10 21:35
一些扭曲Distort特效也在滤镜中比较常见,而且如果在视频拍摄的时候使用则一般会比较有趣,如在Mac电脑上的PhotoBooth软件拍摄就有很多变形的Effect。这里介绍几种特效包括有:挤压(pinch)、球面特效(Spherize)、漩涡(Swirl)、波浪(Wave)等,这几个特效在PhotoSprite软件中都有代码。其他的一些变形也可以根据公式写出来,写出自己独特的一些变形特效出来。
这些特效都是对像素的位置进行改变,而不改变像素值,利用一些数学上的变换公式来进行。
原图:
l 挤压效果
代码:
// 弧度、半径 double radian, radius; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // 当前点与图像中心点的偏移量 offsetX = x - midX; offsetY = y - midY; // 弧度 radian = Math.Atan2(offsetY, offsetX); // 半径 radius = Math.Sqrt(offsetX * offsetX + offsetY * offsetY); radius = Math.Sqrt(radius) * degree; // 映射实际像素点 X = (int)(radius * Math.Cos(radian)) + midX; Y = (int)(radius * Math.Sin(radian)) + midY; // 边界约束 if (X < 0) X = 0; if (X >= width) X = width - 1; if (Y < 0) Y = 0; if (Y >= height) Y = height - 1; src = (byte*)srcScan0 + Y * stride + X * BPP; dst[3] = src[3]; // A dst[2] = src[2]; // R dst[1] = src[1]; // G dst[0] = src[0]; // B dst += BPP; } // x dst += offset; } // y }
l 球面效果
代码:
// 弧度、半径 double radian, radius; int midX = width / 2; int midY = height / 2; // Max(midX, midY) double maxMidXY = (midX > midY ? midX : midY); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // 当前点与图像中心点的偏移量 offsetX = x - midX; offsetY = y - midY; // 弧度 radian = Math.Atan2(offsetY, offsetX); // 注意,这里并非实际半径 radius = (offsetX * offsetX + offsetY * offsetY) / maxMidXY; // 映射实际像素点 X = (int)(radius * Math.Cos(radian)) + midX; Y = (int)(radius * Math.Sin(radian)) + midY; // 边界约束 if (X < 0) X = 0; if (X >= width) X = width - 1; if (Y < 0) Y = 0; if (Y >= height) Y = height - 1; src = (byte*)srcScan0 + Y * stride + X * BPP; dst[3] = src[3]; // A dst[2] = src[2]; // R dst[1] = src[1]; // G dst[0] = src[0]; // B dst += BPP; } // x dst += offset; } // y }
l 漩涡效果
代码:
// 弧度、半径 double radian, radius; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // 当前点与图像中心点的偏移量 offsetX = x - midX; offsetY = y - midY; // 弧度 radian = Math.Atan2(offsetY, offsetX); // 半径,即两点间的距离 radius = Math.Sqrt(offsetX * offsetX + offsetY * offsetY); // 映射实际像素点 X = (int)(radius * Math.Cos(radian + swirlDegree * radius)) + midX; Y = (int)(radius * Math.Sin(radian + swirlDegree * radius)) + midY; // 边界约束 if (X < 0) X = 0; if (X >= width) X = width - 1; if (Y < 0) Y = 0; if (Y >= height) Y = height - 1; src = (byte*)srcScan0 + Y * stride + X * BPP; dst[3] = src[3]; // A dst[2] = src[2]; // R dst[1] = src[1]; // G dst[0] = src[0]; // B dst += BPP; } // x dst += offset; } // y }
l 波浪效果
代码:
double PI2 = Math.PI * 2.0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { X = (int)(degree * Math.Sin(PI2 * y / 128.0)) + x; Y = (int)(degree * Math.Cos(PI2 * x / 128.0)) + y; // 边界约束 if (X < 0) X = 0; if (X >= width) X = width - 1; if (Y < 0) Y = 0; if (Y >= height) Y = height - 1; src = (byte*)srcScan0 + Y * stride + X * BPP; dst[3] = src[3]; // A dst[2] = src[2]; // R dst[1] = src[1]; // G dst[0] = src[0]; // B dst += BPP; } // x dst += offset; } // y }
- 滤镜之变形Distort特效
- 滤镜之颜色特效
- 滤镜之纹理Texture特效
- /LGC图形渲染/图像处理系列之扭曲(distort)
- RevealTrans滤镜特效小记
- css基础--滤镜特效
- ps 滤镜特效
- 图像特效---漫画滤镜
- 图像特效---连环画滤镜
- 图像特效---马赛克滤镜
- 图像特效---Wave滤镜
- 图像特效---Swirl滤镜
- 图像特效---水彩画滤镜
- css3中的滤镜特效
- 图像特效---旋转模糊滤镜
- 图像特效---(Instagram)1977滤镜
- 图像特效---怀旧风格滤镜
- 图像特效---暗调滤镜
- 一点关于android的个人感受
- Java transient关键字使用小结及一些需要注意的细节
- 数论———素数测试
- 百度校招-等待百度的那些日子里
- 枚举类 学习笔记(一)
- 滤镜之变形Distort特效
- java chapter07-1
- JBoss 系列二十二:JBossCache 复制示例
- 如何理解二叉树的先序遍历程序
- 黑马程序员_交通灯管理系统_10
- ibatis中resultMap
- hdu 2089 不要62 (数位DP)
- java chapter07-2
- 写数据结构代码遇到的一些小问题(更新中)