源碼下載:http://yunpan.cn/c3iNuHFFAcr8h  访问密码 8e48

還是先來看下截圖:

實現了幾個效果:放大、縮小、旋轉、左右翻轉、上下翻轉,亮度變化、灰度圖、對比度、高斯模糊。

放大、縮小代碼:

private void scale(float x)
{
scale_ *= x;
using (var ds = board_.CreateDrawingSession())
{
ds.Transform = Matrix3x2.CreateScale(scale_);
ds.Clear(Colors.Black);
ds.DrawImage(oriImage_);
} transform.Invalidate();
} private void zoomIn_Click(object sender, RoutedEventArgs e)
{
scale(1.1f);
} private void zoomOut_Click(object sender, RoutedEventArgs e)
{
scale( / 1.1f);
}

旋轉代碼(注意,默認轉動方向是鐘錶方向——順時針):

private void rotate_Click(object sender, RoutedEventArgs e)
{
rotate_radians_ += ;
using (var ds = board_.CreateDrawingSession())
{
ds.Transform = Matrix3x2.CreateRotation(rotate_radians_ * (float)Math.PI / , new Vector2((float)oriImageRc_.Width / 2.0f, (float)oriImageRc_.Height / 2.0f));
ds.Clear(Colors.Black);
ds.DrawImage(oriImage_);
} transform.Invalidate();
}

左右、上下翻轉代碼:

private void left_right_Click(object sender, RoutedEventArgs e)
{
left_right_direction_ = -left_right_direction_; using (var ds = board_.CreateDrawingSession())
{
ds.Transform = Matrix3x2.CreateScale(new Vector2(left_right_direction_, top_bottom_direction_), new Vector2((float)oriImageRc_.Width / 2.0f, (float)oriImageRc_.Height / 2.0f));
ds.Clear(Colors.Black);
ds.DrawImage(oriImage_);
} transform.Invalidate();
} private void top_bottom_Click(object sender, RoutedEventArgs e)
{
top_bottom_direction_ = -top_bottom_direction_; using (var ds = board_.CreateDrawingSession())
{
ds.Transform = Matrix3x2.CreateScale(new Vector2(left_right_direction_, top_bottom_direction_), new Vector2((float)oriImageRc_.Width / 2.0f, (float)oriImageRc_.Height / 2.0f));
ds.Clear(Colors.Black);
ds.DrawImage(oriImage_);
} transform.Invalidate();
}

亮度、灰度、對比度、高斯,均使用Effect效果,其效果放在名字空間:

Microsoft.Graphics.Canvas.Effects

具體代碼:

亮度,注意,我使用了WhitePoint,還有BlackPoint,請讀者自己試驗效果。而且亮度的範圍為:[0-1),注意閉包關係。

private void lightSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
if (board_ == null) return; using (var ds = board_.CreateDrawingSession())
{
Microsoft.Graphics.Canvas.Effects.BrightnessEffect brightness = new Microsoft.Graphics.Canvas.Effects.BrightnessEffect();
if (e.NewValue >= 0.000001)
{
brightness.WhitePoint = new Vector2(, (float)e.NewValue);
}
else
{
brightness.WhitePoint = new Vector2(-(float)e.NewValue, );
} brightness.Source = oriImage_; ds.Clear(Colors.Black);
ds.DrawImage(brightness);
} transform.Invalidate();
}

灰度:

        private void gray_Click(object sender, RoutedEventArgs e)
{
Microsoft.Graphics.Canvas.Effects.GrayscaleEffect grayEffect = new Microsoft.Graphics.Canvas.Effects.GrayscaleEffect();
grayEffect.Source = oriImage_; using (var ds = board_.CreateDrawingSession())
{
ds.Clear(Colors.Black);
ds.DrawImage(grayEffect);
}
transform.Invalidate();
}

對比度:

        private void constrastSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
if (board_ == null) return; Microsoft.Graphics.Canvas.Effects.ContrastEffect constrastEffect = new Microsoft.Graphics.Canvas.Effects.ContrastEffect();
constrastEffect.Contrast = (float)e.NewValue;
constrastEffect.Source = oriImage_; using (var ds = board_.CreateDrawingSession())
{
ds.Clear(Colors.Black);
ds.DrawImage(constrastEffect);
}
transform.Invalidate();
}

高斯:

private void gaussianSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
if (board_ == null) return; Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect gaussianEffect = new Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect();
gaussianEffect.BlurAmount = (float)e.NewValue;
gaussianEffect.Source = oriImage_; using (var ds = board_.CreateDrawingSession())
{
ds.Clear(Colors.Black);
ds.DrawImage(gaussianEffect);
}
transform.Invalidate();
}

【WIN10】WIN2D——圖像處理的更多相关文章

  1. 在 Windows 上遇到非常多 TIME_WAIT 連線時應如何處理

        我們公司所代管的網站裡,有幾個流量是非常大的,在尖峰的時刻同時上線人數可能高達數千到數萬人,而在這個時候如果使用 netstat 或 TCPView 查看所有 TCP 連線時就會看到非常多處於 ...

  2. PTA題目的處理(一)

    **題目1:A乘B** **實驗代碼** #include <stdio.h> #include <stdlib.h> int main() { signed int a,b; ...

  3. T-SQL 簡易小數處理

    今天因應同事提的一則需求,寫了一段 CASE WHEN 的整數與小數處理 過程中居然踩了個雷,特此記錄下來 首先,需求如下: 當內容為整數或零時則去掉尾端的小數否則就顯示原本的小數內容 若內容為 NU ...

  4. linux缺頁異常處理--內核空間[v3.10]

    缺頁異常被觸發通常有兩種情況—— 1.程序設計的不當導致訪問了非法的地址 2.訪問的地址是合法的,但是該地址還未分配物理頁框 下面解釋一下第二種情況,這是虛擬內存管理的一個特性.盡管每個進程獨立擁有3 ...

  5. iOS/Android/Web Url Encode空格處理 原文連結:http://read01.com/3gDO.html

    iOS/Android/Web Url Encode空格處理 原文連結:http://read01.com/3gDO.html 前言 這裡只是講一個故事,一個發生在我身上的真實的故事.曾經,我以為搞加 ...

  6. 整理幾種常見PCB表面處理的優缺點

    這只是一篇整理文,而且我個人僅從事過後段的電路板組裝,而未從事過電路板製程,所以有些見解純粹只是個人看法,如果有些不一樣的聲音或錯誤也歡迎留言討論. 隨著時代的演進,科技的進步,環保的要求,電子業也隨 ...

  7. C++ 檔案、資料夾、路徑處理函式庫:boost::filesystem

    原帖:https://tokyo.zxproxy.com/browse.php?u=uG7kXsFlW1ZmaxKEvCzu8HrCJ0bXIAddA1s5dtIUZ%2FYzM1u9JI7jjKLT ...

  8. PTA题目的處理(四)

    题目7-3 求交错序列前N项和 1.实验代码 #include <stdio.h> //#include <stdlib.h> int main() { ,N; double ...

  9. SpringBoot使用maven插件打包時報:[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException的處理方案

    SpringBoot使用maven插件打包時報:[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExec ...

随机推荐

  1. BFC的个人理解

    BFC是Block Formatting Context (块级格式化上下文)的缩写,是一个独立的渲染区域,这个东西的存在是为了隔绝一些内部子元素对外部元素的影响. 例如: 我们用overflow:h ...

  2. Python基础【day03】:文件操作(六)

    一.概述 我们工作中需要经常操作文件,下面就讲讲如何用Python操作文件 1.文件操作的流程: 打开文件,得到文件句柄赋值给一个变量 通过文件句柄,对文件进行操作 关闭文件 二.入门 1.语法 op ...

  3. npm install --save

    1. npm install:本地安装 2. npm install -g:全局安装 我们在使用 npm install 安装模块或插件时,有两种命令把它们写入到 package.json 文件中去, ...

  4. 20155236 2016-2017-2 《Java程序设计》第八周学习总结

    20155236 2016-2017-2 <Java程序设计>第八周学习总结 教材学习内容总结 通用API 日志 1.日志API简介:java.util.logging包中提供了日志功能相 ...

  5. shell 检测安装包

    检测 wget 是否存在 rpm -q wget >/dev/null ];then echo "install wget,Please wait..." yum -y in ...

  6. HDU 1875 畅通工程再续 最小生成树问题

    题目描述:输入一个T,表示有T组测试数据,然后每组测试数据有一个C,表示在一个湖里面有C座岛屿,现在要在岛屿之间修建桥,可以修建必须满足的条件是岛与岛之间的距离在10到1000的范围内,然后给出每座岛 ...

  7. blog迁移

    blog迁移到: https://github.com/for-firecat/

  8. Explain EV in /proc/bus/input/devices data【转】

    转自:https://unix.stackexchange.com/questions/74903/explain-ev-in-proc-bus-input-devices-data It repre ...

  9. TypeError: Object of type 'int64' is not JSON serializable

    错误类型:TypeError: Object of type 'int64' is not JSON serializable 错误场景:对Numpy和Pandas结果进行json.dumps报错 错 ...

  10. SUSE Enterprise Server 12 SP3 64 设置防火墙开放8080端口,出现Unsafe permissions for file /etc/sysconfig/SuSEfirewall2 to be sourced

    SUSE Enterprise Server  12 SP3 64 设置防火墙开放8080端口时出现  Unsafe permissions for file /etc/sysconfig/SuSEf ...