原文: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. ios开发不能不知的动态修复bug补丁第三方库JSPatch 使用学习:JSPatch导入、和使用、.js文件传输加解密

    JSPatch ios开发不能不知的动态修复bug补丁第三方库JSPatch 使用学习:JSPatch导入.和使用..js文件传输加解密 ios开发面临审核周期长,修复bug延迟等让人无奈的问题,所以 ...

  2. SpringMVC大坑一枚:ContentNegotiatingViewResolver可能不利于SEO

    广大站长都有关注自己网站被搜索引擎收录的习惯,最近用百度.360等搜索引擎,查看了自己网站的一些情况,使用命令"site:fansunion.cn". 我发现了一些异常信息,不止一 ...

  3. Thermal zone monitoring in an electronic device

    FIELD One embodiment of the invention relates to a closed loop thermal control process in a portable ...

  4. eclipse上springCloud分布式微服务搭建-干货

    一.创建maven父工程(pom) pom.xml如下: eureka: client: registerWithEureka:false fetchRegistry:false serviceUrl ...

  5. Leetcode--easy系列1

    近期開始刷Leetcode题目.花了一个星期先完毕了easy难度级别的题目,easy级别的题目思路比較简单,但不一定就直接AC了,主要是问题要考虑全然.特别是对特殊情况的处理. #6 ZigZag C ...

  6. 《iOS8 Swift编程指南》类书图像

    终于拿到了样书.虽然已经猜到这将是一本很厚的书(63万字),但要真正看到实体书或者当我吃了一惊: 从以下这张照片看则更直观了.居然比艾伦.J.马库斯的<投资学>(634页)还要厚: 这本书 ...

  7. 构建工具Gradle

    1.Summary   从Android团队开始宣布放弃Eclipse转投Android Studio时,构建工具Gradle进入了Android开发者的视野.而随着热修复.插件化.编译时注解的流行, ...

  8. JackSon fasterxml学习

    概述 Jackson框架是基于Java平台的一套数据处理工具,被称为"最好的JavaJson解析器".  Jackson框架包含了3个核心库:streaming,databind, ...

  9. Eclipse使用技巧总结(四)——代码重构专题

    二十四.重命名 这样重命名就方便多了,不需要一个一个去改了 二十五.移动类和方法 二十六.改变方法 二十七.转换匿名内部类到外部 二十八.提取接口 二十九.抽取成单独方法: Refactor--> ...

  10. DDD实战7 对项目进行单元测试

    此次采用的方法是 创建一个单元测试项目 在其中利用HttpClient 模拟浏览器 webapi 进行post请求来验证程序. [TestClass] public class ProductTest ...