public static  void ChangeColour(this Bitmap bmp, byte inColourR, byte inColourG, byte inColourB, byte outColourR, byte outColourG, byte outColourB)
{
// Specify a pixel format.
PixelFormat pxf = PixelFormat.Format24bppRgb; // Lock the bitmap's bits.
Rectangle rect = new Rectangle(, , bmp.Width, bmp.Height);
BitmapData bmpData =
bmp.LockBits(rect, ImageLockMode.ReadWrite,
pxf); // Get the address of the first line.
IntPtr ptr = bmpData.Scan0; // Declare an array to hold the bytes of the bitmap.
// int numBytes = bmp.Width * bmp.Height * 3;
int numBytes = bmpData.Stride * bmp.Height;
byte[] rgbValues = new byte[numBytes]; // Copy the RGB values into the array.
Marshal.Copy(ptr, rgbValues, , numBytes); // Manipulate the bitmap
for (int counter = ; counter < rgbValues.Length; counter += )
{
if (rgbValues[counter] != inColourR &&
rgbValues[counter + ] != inColourG &&
rgbValues[counter + ] != inColourB)
{
rgbValues[counter] = outColourR;
rgbValues[counter + ] = outColourG;
rgbValues[counter + ] = outColourB;
}
} // Copy the RGB values back to the bitmap
Marshal.Copy(rgbValues, , ptr, numBytes); // Unlock the bits.
bmp.UnlockBits(bmpData);
}
  public unsafe void ChangeColour(ref Bitmap bmp, byte inColourR, byte inColourG, byte inColourB, byte outColourR, byte outColourG, byte outColourB, int k)
{
// Specify a pixel format.
PixelFormat pxf = PixelFormat.Format24bppRgb; // Lock the bitmap's bits.
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(, , bmp.Width, bmp.Height);
BitmapData bmpData =
bmp.LockBits(rect, ImageLockMode.ReadWrite,
pxf); // Get the address of the first line.
var bp =(byte*) bmpData.Scan0.ToPointer();
for (int i = ; i != bmpData.Height; i++)
{
for (int j = ; j != bmpData.Width; j++)
{
//0.3R+0.59G+0.11B
if (bp[i * bmpData.Stride + j * ] == inColourB && bp[i * bmpData.Stride + j * + ] == inColourG && bp[i * bmpData.Stride + j * + ] == inColourR)
{
bp[i * bmpData.Stride + j * ] = outColourB;
bp[i * bmpData.Stride + j * + ] = outColourG;
bp[i * bmpData.Stride + j * + ] = outColourR;
//float value = 0.11F * bp[i * bmpData.Stride + j * 3] + 0.59F * bp[i * bmpData.Stride + j * 3 + 1] +
// 0.3F * bp[i * bmpData.Stride + j * 3 + 2];
}
}
} bmp.UnlockBits(bmpData); }

c# 快速修改图片颜色的更多相关文章

  1. WPF 修改图片颜色

    原文:WPF 修改图片颜色 本文告诉大家如何修改图片的颜色,如去掉图片的蓝色 在 WPF 可以使用很多图片处理的方法,本文告诉大家的是一个图片处理,可以把处理的图片保存在文件. 在阅读本文,我假设大家 ...

  2. xml代码修改图片颜色

    <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http ...

  3. Android动态修改图片颜色的实现方式分析

    版权声明:本文为博主原创文章,未经博主允许不得转载. 1.修改色相.饱和度.亮度 参看:http://blog.csdn.NET/sjf0115/article/details/7267063 2.使 ...

  4. 2018-8-10-WPF-修改图片颜色

    title author date CreateTime categories WPF 修改图片颜色 lindexi 2018-08-10 19:16:53 +0800 2018-07-03 15:4 ...

  5. CorelDRAW快速去除图片背景颜色

    当我们需要从网上借助一些素材图片在CorelDRAW中运用时,往往需要去掉图片的背景颜色.本文小编分享CDR中如何快速去除图片背景颜色的方法,通过此方法可以做简单的照片抠图.合成. 1. 打开Core ...

  6. IOS: 使用imageIO获取和修改图片的exif信息

    使用imageIO获取和修改图片的exif信息 一幅图片除了包含我们能看见的像素信息,背后还包含了拍摄时间,光圈大小,曝光等信息.UIImage类将这些细节信息都隐藏了起来,只提供我们关心的图片尺寸, ...

  7. 利用Photoshop修改图片以达到投稿要求

    摘自:http://www.dxy.cn/bbs/thread/8602152#8602152 利用Photoshop修改图片以达到投稿要求 软件版本为Photoshop CS V8.0.1(中文版) ...

  8. tabbarItem字体及图片颜色设置

    tabbarItem设置图片后运行往往与我们原始图片颜色有出入,这是因为在默认情况下,未选中状态图片和字体颜色为灰色,选中状态下图片和字体颜色为蓝色.   UIImage 在呈现(render)时会选 ...

  9. Android--ColorMatrix改变图片颜色

    前言 本篇博客讲解如何通过改变图片像素点RGB的值的方式,在Android中改变图片的颜色.在最后将以一个简单的Demo来作为演示. 本篇博客的主要内容: ColorMatrix 使用ColorMat ...

随机推荐

  1. UIButton的几种触发方式

    1.说明 说明:由于是在"iOS 模拟器"中测试的,所以不能用手指,只能用鼠标. 1)UIControlEventTouchDown 指鼠标左键按下(注:只是"按下&qu ...

  2. java 实验2 类

    共5道大题  最后一题为自动洗牌发牌系统 1) 编写一个类实现银行帐户的概念.包括的属性有:帐号.储户姓名.地址.存款余额,包括的方法有:存款.取款.查询.计算利息.累加利息等. public cla ...

  3. javascript中var that=this

    在JavaScript中,this代表的是当前对象. $(‘#conten').click(function(){ //this是被点击的#conten var that = this; $(‘.co ...

  4. docker容器管理及网络管理

    防火墙规则—— INPUT 主要用于主机防火墙,设置规则屏蔽处理进入本机的数据包示例:禁止10.180.100.141这个机器访问我本机的web服务iptables -t filter -A INPU ...

  5. 通用动态树(Link-Cut Tree)模板

    一个没有维护任何东西的动态树模板 忘了怎么写可以直接来粘 int ch[300010][2], fa[300010], st[300010]; bool lazy[300010]; bool nroo ...

  6. AJAX发送json,SpringMVC 接收JSON,@RequestBody

    需求:JQuery ajax前台,采用 POST请求 发送json,后台使用SpringMVC接收json并处理 前台: $.ajax({ url:"请求地址", type:&qu ...

  7. Xilinx FPGA使用——ROM初始化文件

    在调用ROM的IP Core时,需要对其进行初始化,利用MATLAB生成其初始化数据文件. 工具:ISE 14.7.MATLAB.notepad++ 废话不多说,直接上MATLAB代码,生成了一个10 ...

  8. 对结构化学习(structured learning)的理解

    接触深度学习以来一直接触的概念都是回归,分类,偶尔接触到结构化学习的概念,似懂非懂的糊弄过去,实在是不负责的表现 翻阅维基百科https://en.wikipedia.org/wiki/Structu ...

  9. GDI绘图写的简单扫雷

    由于没话多少时间,这个扫雷我只实现了主要功能(扫雷功能,递归实现) 废话不多说,直接上代码 using System; using System.Collections.Generic; using ...

  10. Spring学习笔记(四)—— Spring中的AOP

    一.AOP概述 AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.O ...