原文: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. Android SqlDelight具体解释和Demo样例

    一.简单介绍 SQLDelight 和 SqlBrite 是 Square 公司推出的一个 Android 平台数据库解决方式. 在了解这个两个东西前,必须先得有Andorid的Sqlite的知识(S ...

  2. WPF随笔(九)--使用路径动画模拟管道流体流向

    原文:WPF随笔(九)--使用路径动画模拟管道流体流向 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/lordwish/article/detail ...

  3. Database Vault注冊

    默认情况下,在安装好Database Vault组件的Oracle HOme下创建的数据库是没有注冊Database Vault的. 1)停EM.监听.数据库 2)启用Database Vault 在 ...

  4. 【t014】拯数

    [题目链接]:http://noi.qz5z.com/viewtask.asp?id=t014 [题意] [题解] 这个锁的序列,如果把末尾的0去掉; 然后再倒过来; 那么就是这个序列对应的格雷码了; ...

  5. 《Windows核心编程》之“完成端口”(对所有IO都是如此,不仅仅是对socket)

    <Windows核心编程>第10章开头部分一再强调:“IO Completion Port”是“构建高性能.可升缩的应用程序”的最佳设施之一,它不仅适用于处理设备IO,也适用于其它越来越多 ...

  6. CreateFileMapping和MapViewOfFile函数

    大家都是到PG是分布式网络事务处理数据库,与其他数据库优点之一就在于服务器与客户的交流是一对一的,所谓一对一是指,针对客户的每一连接服务器都会产生一个进程为其服务,那么问题就来了,这些进程间是如何交互 ...

  7. java-线程-基础

    线程状态及转化 借用网上的一幅图: 说明: 线程一共分为5种状态 新建状态(new) 线程对象被创建后,就进入了新建状态,例如:Thread t = new Thread(); 就绪状态(Runnab ...

  8. linux 网卡配置文件详解

    配置文件位置:/etc/sysconfig/network-scripts/ifcfg-eth0 1. DEVICE=eth0 网卡的名字 2. HWADDR=00:0c:29:90:89:d9 HW ...

  9. matlab 图像的保存

    gcf:获取当前显示图像的句柄: 默认 plot 的 position 是 [232 246 560 420] 0. save >> A = randn(3, 4); >> B ...

  10. Spring 4 MVC+Apache Tiles 3 Example

    In this post we will integrate Apache Tiles 3 with Spring MVC 4, using annotation-based configuratio ...