原文: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哈哈镜效果的更多相关文章

  1. Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法

    原文:Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法 前面章节中介绍了二值图像的形态学算法,这里讲一下灰度图的形态学算法,主要是公式,代码略. 1,膨胀算法 2,腐蚀算法 3 ...

  2. Win8 Metro(C#)数字图像处理--4图像颜色空间描述

    原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述  图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...

  3. Win8 Metro(C#)数字图像处理--3.2图像方差计算

    原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...

  4. Win8 Metro(C#)数字图像处理--3.3图像直方图计算

    原文:Win8 Metro(C#)数字图像处理--3.3图像直方图计算 /// <summary> /// Get the array of histrgram. /// </sum ...

  5. Win8 Metro(C#)数字图像处理--3.4图像信息熵计算

    原文:Win8 Metro(C#)数字图像处理--3.4图像信息熵计算 [函数代码] /// <summary> /// Entropy of one image. /// </su ...

  6. Win8 Metro(C#)数字图像处理--3.5图像形心计算

    原文:Win8 Metro(C#)数字图像处理--3.5图像形心计算 /// <summary> /// Get the center of the object in an image. ...

  7. Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效

    原文:Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效 /// <summary> /// Image merge process. /// </summar ...

  8. Win8 Metro(C#)数字图像处理--3.1图像均值计算

    原文:Win8 Metro(C#)数字图像处理--3.1图像均值计算 /// <summary> /// Mean value computing. /// </summary> ...

  9. Win8 Metro(C#)数字图像处理--2.74图像凸包计算

    原文:Win8 Metro(C#)数字图像处理--2.74图像凸包计算 /// <summary> /// Convex Hull compute. /// </summary> ...

随机推荐

  1. MySQL key分区(五)

    具体描写叙述总结请看MySQL分区(一) 样例:该样例为本人个人学习总结分享->具体说明-->有问题欢迎前来交流

  2. [TypeScript] Using ES6 and ESNext with TypeScript

    TypeScript is very particular about what is and isn't allowed in a TS file to protect you from commo ...

  3. webcollector + selenium 爬取空间相册图片

    package cn.hb.util; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWr ...

  4. 你的服务器没有正确响应Token验证的解决方法

    你的服务器没有正确响应Token验证,请阅读消息接口使用指南 微信 微信公众平台开发模式 平台 消息 接口 启用 URL Token作者:http://txw1958.cnblogs.com/ 原文: ...

  5. ASP.Net请求小周期

    另一篇另篇2 ASP.NET请求处理全过程 一个ASP.NET请求过程中,从浏览器中发出一个Web请求 到 这个请求被响应并显示在浏览器中的过程中究竟会发生哪些不同的事件,当我们进入这个事件之旅时,我 ...

  6. YII2.0多条件查询升级版

    $query = self::find()->andFilterWhere(['v_type' => $v_type])->andFilterWhere(['like', 'a_na ...

  7. 为什么台湾人工智能可能抢输大陆?(XPU时代来临)

    到了 2020 年,每 3 支手机,就会有一支内建有 AI 芯片. 但目前浮出水面的 AI 芯片新创,几乎都是大陆公司. 为什么台湾这回选择缺席? 「我听说 CPU.GPU,没有听过 NPU? 」11 ...

  8. Android开发中如何加载API源码帮助开发

    在eclipse中添加android源码既可以帮助我们的开发,又能使我们边开发边学习. android环境的搭建:http://blog.csdn.net/dawanganban/article/de ...

  9. 写一个去除AI2XAML注释及多余数字位数的WPF窗体程序

    原文:写一个去除AI2XAML注释及多余数字位数的WPF窗体程序 使用正则表达式去除多余注释及冗余数字位,关键代码:            string pattern = @"/b(/d+ ...

  10. 浅谈WPF中对控件的位图特效(WPF Bitmap Effects)

    原文:浅谈WPF中对控件的位图特效(WPF Bitmap Effects) -------------------------------------------------------------- ...