引入DLL:

using AForge.Imaging;
using AForge.Imaging.Filters;
//using AForge.Video.DirectShow;可以使用摄像头图像 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Video.DirectShow;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Windows.Media;
using System.Windows.Media.Imaging; namespace GrayImage
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
} void MainWindow_Loaded(object sender, RoutedEventArgs e)
{ } private Bitmap image = null;
private void Button_Click(object sender, RoutedEventArgs e)
{ GrayPhoto(20); } void GrayPhoto(int stepSize)
{ //素描效果制作
// image = (Bitmap)CurrentPhoto.SourceSource; image = GetBitmap(CurrentPhoto.Source as BitmapSource); if (image.PixelFormat != System.Drawing.Imaging.PixelFormat.Format24bppRgb)
{
Bitmap temp = AForge.Imaging.Image.Clone(image, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
image.Dispose();
image = temp;
}
//转换成灰度图像
Bitmap temBitmap = Grayscale.CommonAlgorithms.BT709.Apply(image);
Bitmap temBitmap2 = (Bitmap)temBitmap.Clone();
Bitmap temBitmap3 = (Bitmap)temBitmap.Clone();
// create filter
Invert filter = new Invert();
// apply the filter
filter.ApplyInPlace(temBitmap2); // create filter 边缘提取
DifferenceEdgeDetector filterEdge = new DifferenceEdgeDetector();
// apply the filter
filterEdge.ApplyInPlace(temBitmap);
// create filter
MoveTowards filterMove = new MoveTowards(temBitmap2, stepSize);
// apply the filter
Bitmap resultImage = filterMove.Apply(temBitmap);
filter.ApplyInPlace(resultImage);
BitmapSource temSource = CreateBitmapSourceFromBitmap(resultImage);
CurrentPhoto.Source = temSource; } Bitmap GetBitmap(BitmapSource m)
{ System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(m.PixelWidth, m.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
System.Drawing.Imaging.BitmapData data = bmp.LockBits(
new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); m.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
bmp.UnlockBits(data); return bmp; } BitmapSource CreateBitmapSourceFromBitmap(Bitmap bitmap)
{ /*-------------------------------------------------------------------------
//Imaging.CreateBitmapSourceFromHBitmap方法,基于所提供的非托管位图和调色板信息的指针,
//返回一个托管的BitmapSource
---------------------------------------------------------------------------*/ IntPtr ip = bitmap.GetHbitmap();//从GDI+ Bitmap创建GDI位图对象
BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
return bitmapSource; } }
}

  

C# 利用AForge.NET开源类库实现 图像素描效果的更多相关文章

  1. dropzonejs中文翻译手册 DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.

    http://wxb.github.io/dropzonejs.com.zh-CN/dropzonezh-CN/ 由于项目需要,完成一个web的图片拖拽上传,也就顺便学习和了解了一下前端的比较新的技术 ...

  2. C#常用开源类库

    一.AOP框架        Encase 是C#编写开发的为.NET平台提供的AOP框架.Encase 独特的提供了把方面(aspects)部署到运行时代码,而其它AOP框架依赖配置文件的方式.这种 ...

  3. DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.

    DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库. 它是轻量级的,不依赖任何其他类库(如JQuery)并且高度可定制. 试试看! 将文件拖至此处或点击上传.(这仅仅是 dropzo ...

  4. C# 利用AForge进行摄像头信息采集

    概述 AForge.NET是一个专门为开发者和研究者基于C#框架设计的,提供了不同的类库和关于类库的资源,还有很多应用程序例子,包括计算机视觉与人工智能,图像处理,神经网络,遗传算法,机器学习,机器人 ...

  5. [转]C#常用开源类库收集

    .net PDF 类库 PDFsharp PDFsharp是一款可以让.NET框架支持的任何语言很容易的创建PDF文件的类库. ASP.NET FO PDF FO PDF 是一款C#编写类似于ASP. ...

  6. C#开源类库

    PDFsharp PDFsharp是一款可以让.NET框架支持的任何语言很容易的创建PDF文件的类库. ASP.NET FO PDF FO PDF 是一款C#编写类似于ASP.NET服务器控件的控件. ...

  7. c# 利用AForge和百度AI开发实时人脸识别

    baiduAIFaceIdentify项目是C#语言,集成百度AI的SDK利用AForge开发的实时人脸识别的小demo,里边包含了人脸检测识别,人脸注册,人脸登录等功能 人脸实时检测识别功能 思路是 ...

  8. .net开源框架开源类库(整理)

    源:http://www.cnblogs.com/chinanetwind/p/3715809.html 常用库 Json.NET https://github.com/JamesNK/Newtons ...

  9. AForge,Emgu.CV抓拍图像大小

    原文:AForge,Emgu.CV抓拍图像大小 2017年,忙忙碌碌地过去了,象往年一样,依然没有时间上CSDN,博客园. 这一年是打工以来最辛苦的一年. 这一年用了不少自己没有接触过的东西.如人脸识 ...

随机推荐

  1. hadopp 环境搭建

    前序: 首先准备三个虚拟机节点.  配置hosts文件:每个节点都 如下配置: vi /etc/hosts 1. 每个结点分别产生公私密钥 ssh-keygen -t dsa -P '' -f ~/. ...

  2. Delphi 处理异常情况

  3. 接口开发(login、reg)

    接口开发: import flask,json,pymysql,hashlib server = flask.Flask(__name__)# 把当前这个python文件当做一个服务 def my_d ...

  4. 火狐插件simple timer 定时打开指定网页

    今天我要介绍的是火狐浏览器一款插件:Simple Timer,该插件是火狐一个可以添加计时器和定时提醒功能插件,该插件的主要作用就是当你的设置在某一个时刻提醒时,插件会自动弹出通知,并且自动打开你想要 ...

  5. radio赋值法

    一般都会使用attr来使选中: $("#DIV的ID input[name='radio的name'][value="'+动态传的radio的value值+'"]&quo ...

  6. supdf

    https://github.com/sumatrapdfreader/sumatrapdf/tree/master/src c++  java

  7. hdu4507 吉哥系列故事——恨7不成妻[数位DP]

    这题面什么垃圾玩意儿 首先看到问题格式想到数位DP,但是求的是平方和.尝试用数位DP推出. 先尝试拼出和.设$f[len][sum][mod]$表示填到$len$位,已填位置数位和$sum$,数字取余 ...

  8. maven在eclipse运行命令和calss文件没有更新的问题

    使用Eclipse Maven插件[Run As]-[Maven build]时并未为其指定goal或phase 解决方法:  1.使用Eclipse Maven插件[Run As]-[Maven b ...

  9. vue 里面异步加载高德地图

    前言 关于Vue 里面使用异步加载高德地图 项目中其实只有几处需要用到地图,不需要全局引入 在index文件中引入js会明显拖慢首屏加载速度,虽然可以使用异步加载script的方式解决,但是始终觉得不 ...

  10. Python 正则表达式Ⅳ

    repl 参数是一个函数 以下实例中将字符串中的匹配的数字乘以 2: 执行输出结果为: re.compile 函数 compile 函数用于编译正则表达式,生成一个正则表达式( Pattern )对象 ...