原文:Win8Metro(C#)数字图像处理--2.18图像平移变换



[函数名称]

图像平移变换函数TranslationProcess(WriteableBitmap
src,int x,int
y)

[函数代码]

       ///<summary>

       ///
Translation process.

       ///</summary>

       ///<param
name="src">Source image.</param>

       ///<param
name="x">Translate value of x.</param>

       ///<param
name="y">Translate value of y.</param>

       ///<returns></returns>

       publicstaticWriteableBitmap
TranslationProcess(WriteableBitmap src,int
x,int y)////18平移变换

       {

           if(src!=null
)

           {

           int
w = src.PixelWidth;

           int
h = src.PixelHeight;

           WriteableBitmap
translateImage =newWriteableBitmap(w,
h);

           byte[]
temp = src.PixelBuffer.ToArray();

           byte[]
tempMask =newbyte[w
* h * 4];

           for
(int j = 0; j < h; j++)

           {

               for
(int i = 0; i < w; i ++)

               {

                   if
(i + x < 0 || i + x >= w || j + y < 0 || j + y >= h)

                   {

                       tempMask[i * 4 + j * w * 4] = (byte)0;

                       tempMask[i * 4 + 1 + j * w * 4] = (byte)0;

                       tempMask[i * 4 + 2 + j * w * 4] = (byte)0;

                   }

                   else

                   {

                       tempMask[i * 4 + j * w * 4] = (byte)(temp[(i
+ x) * 4 + (j + y) * w * 4]);

                       tempMask[i * 4 + 1 + j * w * 4] = (byte)(temp[(i
+ x) * 4 + 1 + (j + y) * w * 4]);

                       tempMask[i * 4 + 2 + j * w * 4] = (byte)(temp[(i
+ x) * 4 + 2 + (j + y) * w * 4]);

                       tempMask[i * 4 + 3 + j * w * 4] = (byte)(temp[(i
+ x) * 4 + 3 + (j + y) * w * 4]);

                   }

               }

           }

           Stream
sTemp = translateImage.PixelBuffer.AsStream();

           sTemp.Seek(0,
SeekOrigin.Begin);

           sTemp.Write(tempMask, 0, w * 4 * h);

           return
translateImage;

           }

           else

           {

               returnnull;

           }  

       }

[图像效果]

Win8Metro(C#)数字图像处理--2.18图像平移变换的更多相关文章

  1. Win8Metro(C#)数字图像处理--2.3图像反色

    原文:Win8Metro(C#)数字图像处理--2.3图像反色 [函数名称] 图像反色函数ContraryProcess(WriteableBitmap src) [算法说明]     反色公式如下: ...

  2. Win8Metro(C#)数字图像处理--2.33图像非线性变换

    原文:Win8Metro(C#)数字图像处理--2.33图像非线性变换  [函数名称] 图像非线性变换函数NonlinearTransformProcess(WriteableBitmap src ...

  3. Win8Metro(C#)数字图像处理--2.32图像曝光算法

    原文:Win8Metro(C#)数字图像处理--2.32图像曝光算法  [函数名称] 图像曝光函数ExposureProcess(WriteableBitmap src,int exposureV ...

  4. Win8Metro(C#)数字图像处理--2.27图像加法运算

    原文:Win8Metro(C#)数字图像处理--2.27图像加法运算  [函数名称] 图像加法函数AddProcess(WriteableBitmap src, WriteableBitmap a ...

  5. Win8Metro(C#)数字图像处理--2.28图像乘法运算

    原文:Win8Metro(C#)数字图像处理--2.28图像乘法运算  [函数名称] 图像乘法函数MultiplicationProcess(WriteableBitmap src, Writea ...

  6. Win8Metro(C#)数字图像处理--2.29图像除法运算

    原文:Win8Metro(C#)数字图像处理--2.29图像除法运算  [函数名称] 图像除法函数DivisionProcess(WriteableBitmap src, WriteableBit ...

  7. Win8Metro(C#)数字图像处理--2.26图像减法

    原文:Win8Metro(C#)数字图像处理--2.26图像减法  [函数名称] 图像减法函数SubtractionProcess(WriteableBitmap src, WriteableBi ...

  8. Win8Metro(C#)数字图像处理--2.19图像水平镜像

    原文:Win8Metro(C#)数字图像处理--2.19图像水平镜像  [函数名称] 图像水平镜像函数MirrorXProcess(WriteableBitmap src) [函数代码]      ...

  9. Win8Metro(C#)数字图像处理--2.20图像垂直镜像

    原文:Win8Metro(C#)数字图像处理--2.20图像垂直镜像  [函数名称] 图像垂直镜像函数MirrorYProcess(WriteableBitmap src) [函数代码]      ...

随机推荐

  1. 【codeforces 755B】PolandBall and Game

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 一个封装比较完整的FTP类——clsFTP

    前几天,看见园子里面的博友写了一个支持断点续传的FTP类,一时技痒,干脆写了个更完整的clsFtp类.只是我写这个clsFtp不是支持断点续传的目的,而是为了封装FTP几个基本常用的操作接口. 功能 ...

  3. WIN内核线程池函数

    线程池 (本章节中样例都是用 VS2010 编译调试的) 线程池编写必须在 Windows Vista 操作系统(以及以上版本号的操作系统)下,且 C++ 编译器版本号至少是 VS2008 线程池的功 ...

  4. HDU 3605Escape(缩点+网络流之最大流)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3605 本来打算昨天写两道题的,结果这个题卡住了,最后才发现是最后的推断条件出错了,推断满流的条件应该是 ...

  5. FZU Problem 2062 Suneast &amp; Yayamao

    http://acm.fzu.edu.cn/problem.php?pid=2062 标题效果: 给你一个数n,要求求出用多少个数字能够表示1~n的全部数. 思路: 分解为二进制. 对于一个数n.看它 ...

  6. matlab 小波处理工具箱

    1. wavedec:多尺度(multilevel)一维小波分解 [C,L] = wavedec(X,N,'wname') [C,L] = wavedec(X,N,Lo_D,Hi_D) 返回值 L(b ...

  7. windows 10 使用 tricks

    全新的环境变量编辑界面, 全新的[任务管理器]⇒ [性能] 0. 添加开机启动项 将要添加的开机自启动软件的快捷方式添加到如下的路径: C:\Users\hasee\AppData\Roaming\M ...

  8. Android官方教程翻译(1)——创建第一个Android应用

    转载请注明出处:http://blog.csdn.net/dawanganban/article/details/9822431 Building Your First App GETSTARTED ...

  9. 1.在windows下安装rabbitMQ

    a .RabbitMQ是用erLang语言写的,所以我们在安装rabbitMQ之前要先安装erLang. 要安装最新版本的请分别前往 www.erlang.org和www.rabbitmq.com网站 ...

  10. 取消scrollView上下拉升

    if (ios_Vewsion_5_Or_Above) { _scrollView.bounces = NO; } else { for (id subview in _scrollView.subv ...