基于C#和Aforge.net实现图像素描效果
2014-12-01 19:41
417 查看
1 AForge.net是图像处理方面的开源类库,基于C#设计实现的。在这里实现一个简单的图像素描效果。
需要添加以下程序集的引用:
2 具体代码实现
图像是在WPF的Image控件CurrentPhoto上显示的。需要进行BitmapSource到System.Drawing.Bitmap相互转换。
3 效果图
原图:
效果图:
需要添加以下程序集的引用:
using AForge.Imaging; using AForge.Imaging.Filters; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; using System.Windows.Media; using System.Windows.Media.Imaging;
2 具体代码实现
图像是在WPF的Image控件CurrentPhoto上显示的。需要进行BitmapSource到System.Drawing.Bitmap相互转换。
private Bitmap image = null; private void cartoonPaint_MouseDown(object sender, MouseButtonEventArgs e) { //素描效果制作 //image = GetBitmap((BitmapSource)CurrentPhoto.Source); image = GetBitmap(changeImageSource); 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, 30); // apply the filter Bitmap resultImage = filterMove.Apply(temBitmap); filter.ApplyInPlace(resultImage); BitmapSource temSource = CreateBitmapSourceFromBitmap(resultImage); CurrentPhoto.Source = temSource; }
3 效果图
原图:
效果图:
相关文章推荐
- [转]在ASP.NET中如何用C#.NET实现基于表单的验证(一)
- [转]在ASP.NET中如何用C#.NET实现基于表单的验证(二)
- 如何使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- 在ASP.NET中如何用C#.NET实现基于表单的验证
- 类似 MSDN CSDN 导航树效果 ASP.Net(C#) + JavaScript 实现!
- 如何使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- ASP.NET实例:用C#制作超酷的图像效果
- 在ASP.NET中如何用C#.NET实现基于表单的验证
- [导入]如何使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- [转]在ASP.NET中如何用C#.NET实现基于表单的验证(一)
- 一个简单的AJAX实现,基于C#的ASP.Net,包括服务器端的程序代码
- 如何使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- 如何使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- 在ASP.NET中如何用C#.NET实现基于表单的验证
- 使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- 如何使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- 使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- 在ASP.NET中如何用C#.NET实现基于表单的验证
- 如何实现C#.net图像处理
- 在ASP.NET中如何用C#.NET实现基于表单的验证