GDI +:将所有像素定的颜色,同时保留现有的Alpha值 [英] GDI+: Set all pixels to given color while retaining existing alpha value

查看:334
本文介绍了GDI +:将所有像素定的颜色,同时保留现有的Alpha值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是在 System.Drawing.Bitmap 来设置每个像素的RGB分量到一个单一的,纯色的最佳方式?如果可能的话,我想避免手动通过每个像素的循环来做到这一点。

What is the best way to set the RGB components of every pixel in a System.Drawing.Bitmap to a single, solid color? If possible, I'd like to avoid manually looping through each pixel to do this.

请注意:我想从原来的位图保持相同的alpha分量。我只是想改变RGB值。

Note: I want to keep the same alpha component from the original bitmap. I only want to change the RGB values.

我看着使用嘉洛斯颜色映射,但我无法找到任何方式来设置所有像素用两种方法具体给定的颜色。

I looked into using a ColorMatrix or ColorMap, but I couldn't find any way to set all pixels to a specific given color with either approach.

推荐答案

是的,使用嘉洛斯。它应该是这样的:

Yes, use a ColorMatrix. It ought to look like this:

  0  0  0  0  0
  0  0  0  0  0
  0  0  0  0  0 
  0  0  0  1  0 
  R  G  B  0  1

当R,G和B是更换颜色的缩放颜色值(由255.0f除)

Where R, G and B are the scaled color values of the replacement color (divide by 255.0f)

这篇关于GDI +:将所有像素定的颜色,同时保留现有的Alpha值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆