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,博客园. 这一年是打工以来最辛苦的一年. 这一年用了不少自己没有接触过的东西.如人脸识 ...
随机推荐
- mysql的导入导出操作
mysqldump工具基本用法 此方法不适用于大数据备份 备份所有数据库 mysqldump -u root -p --all-databases > all_database_sql 备份my ...
- scala下划线的作用
https://stackoverflow.com/questions/8000903/what-are-all-the-uses-of-an-underscore-in-scala Existent ...
- Delphi ComboBox组件
- php不重新编译,添加模块
本文已安装mysqli模块为例 一:检查 1:首先保证php-fpm能正常启动 2:查看当前已安装的php模块是否有mysqli [root@oldboyedu ~]# /application/ph ...
- Rust 基础学习
所有权: 变量具有唯一所有权.如果一个类型拥有 Copy trait,一个旧的变量在将其赋值给其他变量后仍然可用.除此之外,赋值意味着转移所有权.Rust 不允许自身或其任何部分实现了 Drop tr ...
- linux ftp 添加用户及权限管理
Linux下创建用户是很easy的事情了,只不过不经常去做这些操作,时间久了就容易忘记,顺便配置一下FTP.声明:使用Linux版本release 5.6,并以超级管理员root身份运行. 1.创建用 ...
- AVAYA_Site_administrator软件简单操作
AVAYA_Site_administrator软件简单操作 1.配置软件(第一次登录) 点击File>New>Voice System 在弹出对话框随意输入一个名称 下一步,默认选择 ...
- vsftpd启动报错:vsftpd:500 OOPS: bad bool value in config file for: anonymous_enable
vsftpd启动报错:vsftpd:500 OOPS: bad bool value in config file for: anonymous_enable 今天在调试centos vsftp的时 ...
- Observer-Proxy拦截器 -ES6
在目标对象前嫁接了一个拦截层,外界对该对象的访问都必须通过这层拦截 可实现观察者模式
- (转)window.parent和window.opener区别
下面一段代码是关于window.parent和window.opener区别 来讲的,我们如果要用到iframe的值传到另一框架就要用到window.opener.document.getElemen ...