基于C#和Aforge.net实现图像素描效果

1 AForge.net是图像处理方面的开源类库,基于C#设计实现的。在这里实现一个简单的图像素描效果。
需要添加以下程序集的引用:

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 效果图

原图:

效果图:

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值