Win8 Metro(C#)数字图像处理--2.61哈哈镜效果
原文:Win8 Metro(C#)数字图像处理--2.61哈哈镜效果
[函数名称]
哈哈镜效果函数 WriteableBitmap DistortingMirrorProcess(WriteableBitmap src, int x, int y)
[算法说明]
哈哈镜效果图像实际上是一种图像形变特效而已,对于这个特效,我们可以通过三角变换来实现。
1,对于哈哈镜效果变换,首先它有两个参数,原点坐标和特效影响因子。
对于图像中的像素点P(x,y),假设原点坐标为X,Y,那么,根据三角函数变换可以得到:
当前像素P的相对坐标cX,cY:
/// <summary>
/// Distorting mirror process.
/// </summary>
/// <param name="src">The source image.</param>
/// <param name="x">Origin of coordinates in x direction.</param>
/// <param name="y">Origin of coordinates in y direction.</param>
/// <returns></returns>
public static WriteableBitmap DistortingMirrorProcess(WriteableBitmap src, int x, int y)////哈哈镜特效
{
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap srcImage = new WriteableBitmap(w, h);
byte[] temp = src.PixelBuffer.ToArray();
byte[] tempMask = (byte[])temp.Clone();
int radius = 0;
double theta = 0;
int tX = 0;
int tY = 0;
int mapX = 0;
int mapY = 0;
int mapR=0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
tX = i - x;
tY = j - y;
theta = Math.Atan2((double)tY, (double)tX);
radius = (int)Math.Sqrt((double)(tX * tX + tY * tY));
mapR = (int)(Math.Sqrt((double)radius * 100));
mapX = x + (int)(mapR * Math.Cos(theta));
mapY = y + (int)(mapR * Math.Sin(theta));
temp[i * 4 + j * w * 4] = tempMask[mapX * 4 + mapY * w * 4];
temp[i * 4 + 1 + j * w * 4] = tempMask[mapX * 4 + 1 + mapY * w * 4];
temp[i * 4 + 2 + j * w * 4] = tempMask[mapX * 4 + 2 + mapY * w * 4];
}
}
Stream sTemp = srcImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return srcImage;
}
else
{
return null;
}
}
[图像效果]
Win8 Metro(C#)数字图像处理--2.61哈哈镜效果的更多相关文章
- Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法
原文:Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法 前面章节中介绍了二值图像的形态学算法,这里讲一下灰度图的形态学算法,主要是公式,代码略. 1,膨胀算法 2,腐蚀算法 3 ...
- Win8 Metro(C#)数字图像处理--4图像颜色空间描述
原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述 图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...
- Win8 Metro(C#)数字图像处理--3.2图像方差计算
原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...
- Win8 Metro(C#)数字图像处理--3.3图像直方图计算
原文:Win8 Metro(C#)数字图像处理--3.3图像直方图计算 /// <summary> /// Get the array of histrgram. /// </sum ...
- Win8 Metro(C#)数字图像处理--3.4图像信息熵计算
原文:Win8 Metro(C#)数字图像处理--3.4图像信息熵计算 [函数代码] /// <summary> /// Entropy of one image. /// </su ...
- Win8 Metro(C#)数字图像处理--3.5图像形心计算
原文:Win8 Metro(C#)数字图像处理--3.5图像形心计算 /// <summary> /// Get the center of the object in an image. ...
- Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效
原文:Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效 /// <summary> /// Image merge process. /// </summar ...
- Win8 Metro(C#)数字图像处理--3.1图像均值计算
原文:Win8 Metro(C#)数字图像处理--3.1图像均值计算 /// <summary> /// Mean value computing. /// </summary> ...
- Win8 Metro(C#)数字图像处理--2.74图像凸包计算
原文:Win8 Metro(C#)数字图像处理--2.74图像凸包计算 /// <summary> /// Convex Hull compute. /// </summary> ...
随机推荐
- [tmux] Create collections of panes using tmux windows
In tmux, a window is a collection of panes. Creating multiple windows is a great way to organize you ...
- 【转】Boost.Python
http://edyfox.codecarver.org/html/boost_python.html Boost.Python 是 Boost 中的一个组件,使用它能够大大简化用 C++ 为 Pyt ...
- 古语云:工欲善其事必先利其器 --> 最新、最全的 IntelliJ IDEA(2018.3.3) 的介绍、安装、破解、配置与使用
原文:古语云:工欲善其事必先利其器 --> 最新.最全的 IntelliJ IDEA(2018.3.3) 的介绍.安装.破解.配置与使用 一.IntelliJ IDEA 介绍 -> Ecl ...
- 【hdu 1517】A Multiplication Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- SQLite编码
•SQLite编码 •讲师:李明杰 •技术博客:http://www.cnblogs.com/mjios •SQLite3 •在iOS中使用SQLite3,首先要添加库文件libsqlite3.dyl ...
- Erlang中频繁发送远程消息要注意的问题
http://avindev.iteye.com/blog/76373 注:这篇文章可能会有争议,欢迎提出意见 在Erlang中,如果要实现两个远程节点之间的通信,就需要通过网络来实现,对于消息发送, ...
- NOIP模拟 拆网线 - 贪心策略+dp
题目大意: 给一颗n个节点的树,保留最少的边,使得每个连通块的大小都大于等于2,并且连通块的点数和等于k. 题目分析: 要想留下的边数最少,就要尽量多的选择单独的边,这里就要贪心:尽可能多的选择单独的 ...
- WPF入门(三)->几何图形之椭圆形(EllipseGeometry)
原文:WPF入门(三)->几何图形之椭圆形(EllipseGeometry) 我们可以使用EllipseGeometry 来绘制一个椭圆或者圆形的图形 EllipseGeometry类: 表示圆 ...
- 辨异 —— 行星 vs 恒星
star:恒星,planet:行星: 1. 恒星 恒星是指宇宙中靠核聚变产生的能量而自身能发热发光的星体(比如太阳).过去天文学家以为恒星的位置是永恒不变的,以此为名.但事实上,恒星也会按照一定的轨迹 ...
- Maven 学习总结
1. 下载地址 Maven: http://maven.apache.org/download.cgi 2. 为Maven配置本地仓库和远程仓库 修改 Maven 目录中 con ...