源碼下載: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. 开发环境--Pipenv的使用

    1.Pipenv 介绍 Pipenv是基于pip的Python包管理工具,它和pip的用法非常相似,可以看做pip的加强版. pipenv解决了旧的pip+virtualenv+requirement ...

  2. Ajax跨域CORS

    在Ajax2.0中多了CORS允许我们跨域,但是其中有着几种的限制:Origin.Methods.Headers.Credentials 1.Origin 当浏览器用Ajax跨域请求的时候,会带上一个 ...

  3. bzoj千题计划247:bzoj4903: [Ctsc2017]吉夫特

    http://uoj.ac/problem/300 预备知识: C(n,m)是奇数的充要条件是 n&m==m 由卢卡斯定理可以推出 选出的任意相邻两个数a,b 的组合数计算C(a,b)必须是奇 ...

  4. hdu 5079 Square

    http://acm.hdu.edu.cn/showproblem.php?pid=5079 题意: n*n网格,每个格子可以涂黑色或白色,有的格子必须涂黑色 问最大白色正方形边长分别为0,1,2,… ...

  5. 略显犀利的 js 判断闰年

    /** * 判断闰年函数 * @param {number} year 要判断的年份 * @return {bool} 返回布尔值 * * 其实只要满足下面几个条件即可. * 1.普通年能被4整除且不 ...

  6. javascript实现的拖拽回放

    这个功能很简单,直接贴代码啊: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...

  7. Maven私服安装及配置——(十二)

    0.私服实际是B/S架构的,需要通过浏览器访问.访问地址在 nexus-2.12.0-01\conf\nexus.properties中查看.

  8. Binary Representation

    Given a (decimal - e.g. 3.72) number that is passed in as a string, return the binary representation ...

  9. 升级openssh到最新版本

    首先,下载最新版本,传到服务器:http://mirror.aarnet.edu.au/pub/OpenBSD/OpenSSH/portable/ 安装 cd /root/ mkdir ssh_upg ...

  10. vs 调试不进入断点

    背景 或许当时环境不知发了什么神经,就是不调试了.竟然还有这种简单错误. 解决方案---配置管理器---选择debug模式