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,博客园. 这一年是打工以来最辛苦的一年. 这一年用了不少自己没有接触过的东西.如人脸识 ...
随机推荐
- 借用jquery实现:使浏览器的“前进”按钮功能失效
我借用jquery实现了这种效果,但并没有禁用掉浏览器本身的“前进”按钮,以下是代码,希望有用的朋友借鉴以下: $(function () { jQuery(window).bind("un ...
- Java高并发程序设计学习笔记(一):并行简介以及重要概念
转自:https://blog.csdn.net/dataiyangu/article/details/86211544#_28 文章目录为什么需要并行?反对意见大势所趋几个重要的概念同步(synch ...
- RHEL6中LVM逻辑卷管理
1.LVM 基本术语 物理卷(physical volume):物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘. 卷组(Volume Group):卷组建立 ...
- jQuery获取兄弟标签的文本
// 一个div里面有一个span标签和多个button标签,每个button标签都有id,span标签没有id,通过点击其中一个button标签,来获取到span标签的text function ( ...
- VMware:未能将管道连接到虚拟机, 所有的管道范例都在使用中
问题描述:虚拟机下的Ubuntu系统长时间死机无法正常关机,用Windows任务管理器关闭VMware也关不掉,没办法,只能直接关电脑了...重新打开电脑,启动VMware,发现提示客户机已经处于打开 ...
- shell cat EOF 变量自动解析问题
使用如下shell安装node时,一直提示 command not found wget https://mirrors.huaweicloud.com/nodejs/latest-v8.x/node ...
- 【小知识】比较 x^y 和 y^x 的大小
往前翻几个编号相邻的题目翻到了这么一道题,感觉很好奇就做了一下 (upd:我下午问了下出题人做法,他就把题隐藏了……这不太友好啊……所以我补一下题意:) 题意 给你两个整数 $x$ 和 $y$,求 $ ...
- kafka常见命令
基础命令 查看已有topic 进入kafka解压目录:/home/zallds/kafka_2.10-0.10.2.1 执行如下命令,就会列出所有topic [zallds@PUBLIC-26 bin ...
- 7.Go-用户信息和系统文件目录
7.1.获取操作系统用户信息 (1)os包及子包功能 os/exec包,负责执行外部命令 os/singal对输入信息的访问 os/user通过名次或ID 查询用户账号 (2)在os/user中提供了 ...
- centos swap分区
swap分区 通常memory是机器的物理内存,读写速度低于cpu一个量级,但是高于磁盘不止一个量级.所以,程序和数据如果在内存的话,会有非常快的读写速度.但是,内存的造价是要高于磁盘 ...