原文: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 设置图片 Bitmap任意透明度

    两种思路,第一种思路是通过对Bitmap进行操作,将Bitmap的像素值get到一个int[]数组里,因为在android里Bitmap通常是ARGB8888格式,所以最高位就是A通道的值,对齐进行改 ...

  2. 实践-Task

    实践-Task 上篇博文中,我们介绍了Thread和ThreadPool: 多线程异步编程示例和实践-Thread和ThreadPool 本文中我们继续,说一下TPL(Task Parallel Li ...

  3. java常用api2

    calendar calendar=calendar.getInstance(); StringBuilder和C#的用法一样 hashSet无序的,不可重复 LInkedHashSet有序的,不可重 ...

  4. Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/vm10-0-0-19

    输入:service mysqld start 报错: Starting MySQL.. ERROR! The server quit without updating PID file (/usr/ ...

  5. CodeBlocks环境搭建及创建第一个C++程序

    某业界大牛推荐最佳的途径是从raytracing入门,所以本屌开始学习<Ray Tracing In One Weekend>. 该书是基于C++的.本屌从未学过C++.感觉告诉我,要先搭 ...

  6. FPGA综合优化

    1 速度和面积 在全面优化水平将达到速度和面积RTL要利用逻辑拓扑的优势. 供FPGA由于在后端而言缺乏知识,门级优化.普通情况下更高的速度要求更高的并行性以及更大的面积,可是在某些特殊情况下并非这样 ...

  7. Oracle数据库案例整理-Oracle系统执行失败-sql_trace至TRUE导致Oracle在根文件夹中缺乏可用空间

    1.1       述 在"$ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/trace"文件夹下产生大量"oracle_w ...

  8. VS 2017正式版

    Visual Studio 2017正式版发布全纪录 又是一年发布季,微软借着Visual Studio品牌20周年之际,于美国太平洋时间2017年3月7日9点召开发布会议,宣布正式发布新一代开发利器 ...

  9. qLibc 对于C C++都是一个很好的框架,提供Tree Hash Stack String I/O File Time等功能

    qLibc Copyright qLibc is published under 2-clause BSD license known as Simplified BSD License. Pleas ...

  10. WPF 使用 SharpDX 在 D3DImage 显示

    原文:WPF 使用 SharpDX 在 D3DImage 显示 版权声明:博客已迁移到 http://lindexi.gitee.io 欢迎访问.如果当前博客图片看不到,请到 http://linde ...