C# 利用AForge.NET开源类库实现 图像素描效果
引入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开源类库实现 图像素描效果的更多相关文章
- dropzonejs中文翻译手册 DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.
http://wxb.github.io/dropzonejs.com.zh-CN/dropzonezh-CN/ 由于项目需要,完成一个web的图片拖拽上传,也就顺便学习和了解了一下前端的比较新的技术 ...
- C#常用开源类库
一.AOP框架 Encase 是C#编写开发的为.NET平台提供的AOP框架.Encase 独特的提供了把方面(aspects)部署到运行时代码,而其它AOP框架依赖配置文件的方式.这种 ...
- DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.
DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库. 它是轻量级的,不依赖任何其他类库(如JQuery)并且高度可定制. 试试看! 将文件拖至此处或点击上传.(这仅仅是 dropzo ...
- C# 利用AForge进行摄像头信息采集
概述 AForge.NET是一个专门为开发者和研究者基于C#框架设计的,提供了不同的类库和关于类库的资源,还有很多应用程序例子,包括计算机视觉与人工智能,图像处理,神经网络,遗传算法,机器学习,机器人 ...
- [转]C#常用开源类库收集
.net PDF 类库 PDFsharp PDFsharp是一款可以让.NET框架支持的任何语言很容易的创建PDF文件的类库. ASP.NET FO PDF FO PDF 是一款C#编写类似于ASP. ...
- C#开源类库
PDFsharp PDFsharp是一款可以让.NET框架支持的任何语言很容易的创建PDF文件的类库. ASP.NET FO PDF FO PDF 是一款C#编写类似于ASP.NET服务器控件的控件. ...
- c# 利用AForge和百度AI开发实时人脸识别
baiduAIFaceIdentify项目是C#语言,集成百度AI的SDK利用AForge开发的实时人脸识别的小demo,里边包含了人脸检测识别,人脸注册,人脸登录等功能 人脸实时检测识别功能 思路是 ...
- .net开源框架开源类库(整理)
源:http://www.cnblogs.com/chinanetwind/p/3715809.html 常用库 Json.NET https://github.com/JamesNK/Newtons ...
- AForge,Emgu.CV抓拍图像大小
原文:AForge,Emgu.CV抓拍图像大小 2017年,忙忙碌碌地过去了,象往年一样,依然没有时间上CSDN,博客园. 这一年是打工以来最辛苦的一年. 这一年用了不少自己没有接触过的东西.如人脸识 ...
随机推荐
- Clang编译选项和Pass构建
编译选项相关: 想要添加的选项,以我添加的-fdpu为例子 能通过clang --help得到的选项,整体需要一个解析文件(好像在LLVM项目中都是通过后缀名为xxx.td和xxx.def的文件来进行 ...
- PyTorch安装问题解决
现在caffe2被合并到了PyTorch中 git clone https://github.com/pytorch/pytorch pip install -r requirements.txtsu ...
- 从一道索引数据结构面试题看B树、B+树
题目1: Mysql数据库用过吧?l里面的索引是基于什么数据结构. 答:主要是基于Hash表和B+树 题目2: 很好请你说一下B+树的实现细节是什么样的?B-树和B+树有什么区别?联合索引在B+树中如 ...
- php页面禁用错误报告
//禁用错误报告 error_reporting(0);#or ini_set("display_errors","Off"); //开启错误报告 ini_se ...
- spring+mybatis 多数据源的配置
方式一: 参见博客https://www.cnblogs.com/AmbitiousMice/p/6027674.html 此种方式每次需要在调用dao的时候设置对应的数据源. 方式二: 直接在myb ...
- GlusterFS ——分布式卷
GlusterFS概述 全部部署GlusterFS文件系统地址:https://www.cnblogs.com/Mercury-linux/p/12050389.html GlusterFS系统是一个 ...
- MyEclipse使用教程:添加和更新插件(一)
[MyEclipse CI 2019.4.0安装包下载] 通过Eclipse Marketplace目录或各种更新站点类型添加插件来自定义您的Genuitec IDE. Genuitec提供以下IDE ...
- windows2012 下面php7.2 安装mongodb4.0.4的扩展以及操作mongodb的方法
php连接mongodb驱动 的下载页面http://pecl.php.net/package/mongodb 数据插入: $manager = new MongoDB\Driver\Manager( ...
- Python 3标准库 第五章 数学运算
第五章数学运算-----------------------上下文解释:编程时,我们一般也是先给程序定义一些前提(环境变量.描述环境变化的全局变量等),这些“前提”就是上文,然后再编写各功能模块的代码 ...
- Python 正则表达式Ⅴ
正则表达式实例 字符匹配 字符类 特殊https://www.xuanhe.net/字符类