原文:Win8Metro(C#)数字图像处理--2.27图像加法运算



[函数名称]

图像加法函数AddProcess(WriteableBitmap src, WriteableBitmap addSrc)

[函数代码]

        /// <summary>

        /// Add procession of two images(Both of them should be in same size).

        /// </summary>

        /// <param name="src">The first source image.</param>

        /// <param name="addSrc">The second source iamge.</param>

        /// <returns></returns>

        public static WriteableBitmap AddProcess(WriteableBitmap src,WriteableBitmap addSrc)////27图像加法 

        {

            if (src != null)

            {

                int w = src.PixelWidth;

                int h = src.PixelHeight;

                WriteableBitmap addImage = new WriteableBitmap(w, h);

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

                byte[] addTemp = addSrc.PixelBuffer.ToArray();

                byte[] dst = new byte[w * h * 4];

                int r = 0, g = 0, b = 0;

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

                {

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

                    {

                        b = temp[i * 4 + (h - 1 - j) * w * 4] + addTemp[i * 4 + (h - 1 - j) * w * 4];

                        g = temp[i * 4 + 1 + (h - 1 - j) * w * 4] + addTemp[i * 4 + 1 + (h - 1 - j) * w * 4];

                        r = temp[i * 4 + 2 + (h - 1 - j) * w * 4] + addTemp[i * 4 + 2 + (h - 1 - j) * w * 4];

                        dst[i * 4 + j * w * 4] = (byte)(b > 0 ? (b < 255 ? b : 255) : 0);

                        dst[i * 4 + 1 + j * w * 4] = (byte)(g > 0 ? (g < 255 ? g : 255) : 0);

                        dst[i * 4 + 2 + j * w * 4] = (byte)(r > 0 ? (r < 255 ? r : 255) : 0);

                        dst[i * 4 + 3 + j * w * 4] = 0;

                        b = 0; g = 0; r = 0;

                    }

                }

                Stream sTemp = addImage.PixelBuffer.AsStream();

                sTemp.Seek(0, SeekOrigin.Begin);

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

                return addImage;

            }

            else

            {

                return null;

            }      

        }

Win8Metro(C#)数字图像处理--2.27图像加法运算的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. Win8Metro(C#)数字图像处理--2.18图像平移变换

    原文:Win8Metro(C#)数字图像处理--2.18图像平移变换  [函数名称] 图像平移变换函数TranslationProcess(WriteableBitmap src,int x,in ...

随机推荐

  1. [Angular] Observable.catch error handling in Angular

    import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; import 'rxjs/add/opera ...

  2. PHP数组foreach循环如何实现逆序访问?

    PHP数组foreach循环如何实现逆序访问? 一.总结 1.array_reverse($array) :foreach(array_reverse($array) as $key=>$val ...

  3. 从Handler+Message+Looper源代码带你分析Android系统的消息处理机制

    PS一句:不得不说CSDN同步做的非常烂.还得我花了近1个小时恢复这篇博客. 引言 [转载请注明出处:http://blog.csdn.net/feiduclear_up CSDN 废墟的树] 作为A ...

  4. [NPM] Run npm scripts with git hooks

    In this lesson we will look about how we can integrate with git hooks to help enforce a certain leve ...

  5. 使用原生JS+CSS或HTML5实现简单的进度条和滑动条效果(精问)

    使用原生JS+CSS或HTML5实现简单的进度条和滑动条效果(精问) 一.总结 一句话总结:进度条动画效果用animation,自动效果用setIntelval 二.使用原生JS+CSS或HTML5实 ...

  6. [搜索]Trie树的实现

    trie这种树也被称为线索,搜索树. 正如图 以下是用stl 的map来实现 class trie_item_c { public: trie_item_c(){} trie_item_c(const ...

  7. js一些编写的函数

    第一:它是最常见的 function A(){ } 说明 A(); 第二: var B = function(){ } 方法 B();//这是匿名函数 第三: (function () {      ...

  8. [Erlang]Mnesia分布式应用

    http://blog.csdn.net/erlib/article/details/40743687 情景: 设计一个图书管理系统,需求: 1. 基本的增删查改功能; 2. 支持多节点备份(其中一个 ...

  9. sparksql parquet 合并元数据

    java public class ParquetMergeSchema { private static SparkConf conf = new SparkConf().setAppName(&q ...

  10. storm 经常使用类

    弄 <dependency> <groupId>org.apache.storm</groupId> <artifactId>storm-core< ...