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); }

最新文章

  1. bzoj4314
  2. Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.3 + Mariadb 10.1.20 + Nginx 1.10.2 + PHP 7.1.0 + Laravel 5.3 )
  3. sql server 2000数据库 最近经常出现某进程一直占用资源,阻塞?死锁?
  4. macOS安装「oh my zsh」
  5. javascript 导出Excel
  6. phpcms v9无法连接数据库服务器,请检查配置
  7. sublime 实用 快捷键
  8. SQL Server中易混淆的数据类型
  9. MySql 环境配置
  10. scala位压缩与行情转换二进制
  11. 【蓝桥杯真题】地宫取宝(搜索-&gt;记忆化搜索详解)
  12. SharePoint Framework 在web部件中使用第三方样式 - 将第三方样式打到包中
  13. light oj 1422 - Halloween Costumes
  14. springmvc(二) ssm框架整合的各种配置
  15. 安装 RabbitMQ
  16. 二、持久层框架(Hibernate)
  17. java中super和this的使用
  18. 3.10 C++虚基类 虚继承
  19. js判断是否是闰年
  20. AIR程序调用本地默认应用程序打开本地文件

热门文章

  1. 「CF622F」The Sum of the k-th Powers「拉格朗日插值」
  2. HDU6342-2018ACM暑假多校联合训练4-1011-Problem K. Expression in Memories
  3. 不值一提,却又不得不提的“CSS文本超出部分省略号代替”
  4. 3. C/C++笔试面试经典题目三
  5. nRF51822外设应用[2]:GPIOTE的应用-按键检测
  6. centos虚拟机设置静态ip
  7. chmod变更文件或目录的权限
  8. JavaWeb学习笔记(十一)—— JavaWeb开发模式【转】
  9. Android TCP协议的Socket通信
  10. Hibernate Restrictions的运算符