C#图像处理之木刻效果实现方法

作者:沧海一粟…… 时间:2022-05-20 04:28:13 

本文实例讲述了C#图像处理之木刻效果实现方法。分享给大家供大家参考。具体如下:


//木刻效果
public Bitmap PFilterMuKe(Bitmap src)
{
try
{
 Bitmap a = new Bitmap(src);
 Rectangle rect = new Rectangle(0, 0, a.Width, a.Height);
 System.Drawing.Imaging.BitmapData bmpData = a.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
 int stride = bmpData.Stride;
 unsafe
 {
  byte* pIn = (byte*)bmpData.Scan0.ToPointer();
  byte* P;
  int R, G, B;
  int temp = 0;
  for (int y = 0; y < a.Height; y++)
  {
  for (int x = 0; x < a.Width; x++)
  {
   P = pIn;
   B = P[0];
   G = P[1];
   R = P[2];
   temp = (byte)((B + G + R) / 3);
   if (temp >= 122.5)
   {
   P[2] = 0;
   P[1] = 0;
   P[0] = 0;
   }
   else
   {
   P[2] = (byte)255;
   P[1] = (byte)255;
   P[0] = (byte)255;
   }
   pIn += 3;
  }
  pIn += stride - a.Width * 3;
  }
 }
 a.UnlockBits(bmpData);
 return a;
}
catch (Exception e)
{
 MessageBox.Show(e.Message.ToString());
 return null;
}
}

原图:

C#图像处理之木刻效果实现方法

效果图:

C#图像处理之木刻效果实现方法

希望本文所述对大家的C#程序设计有所帮助。

标签:C#,图像
0
投稿

猜你喜欢

  • 使用JMX连接JVM实现过程详解

    2022-07-25 23:05:45
  • 再谈java回调函数

    2023-09-27 19:20:10
  • springboot自动配置原理以及spring.factories文件的作用详解

    2021-12-20 20:19:27
  • 详谈Java中net.sf.json包关于JSON与对象互转的坑

    2023-03-02 12:38:31
  • WebService教程详解(一)

    2022-02-26 09:59:50
  • JAVA格式化时间日期的简单实例

    2022-10-06 09:14:58
  • 聊聊Redis的单线程模型

    2022-02-21 09:20:42
  • java简单模仿win10计算器

    2023-06-25 21:57:20
  • 简单理解java泛型的本质(非类型擦除)

    2023-10-13 03:54:34
  • Java Redis Redisson配置教程详解

    2022-10-13 06:32:39
  • C#中OpenCvSharp 通过特征点匹配图片的方法

    2023-07-14 08:10:55
  • Mybatis中如何进行批量更新(updateBatch)

    2022-10-11 13:42:00
  • Java实现英文猜词游戏的示例代码

    2023-08-07 11:40:39
  • Java数据结构之顺序表和链表精解

    2021-07-01 14:30:39
  • SpringBoot整合Echarts实现用户人数和性别展示功能(详细步骤)

    2023-02-22 00:31:59
  • 字符串替换Replace仅替换第一个字符串匹配项

    2021-10-02 17:36:56
  • mybatisplus逻辑删除基本实现和坑点解决

    2021-05-24 11:35:50
  • c#的params参数使用示例

    2021-10-07 04:53:39
  • java 装饰模式(Decorator Pattern)详解及实例代码

    2023-09-07 03:13:08
  • Java如何通过枚举实现有限状态机

    2021-08-05 04:21:05
  • asp之家 软件编程 m.aspxhome.com