转载自 : http://dearymz.blog.163.com/blog/static/205657420102270658306/
ColorMatrix
2010-03-27 12:06:58| 分类:Game | 标签:|字号大中小 订阅
What Is a Color Matrix?
Just as the co-ordinates x, y, and z define a single point in 3D space, the three color components R (red), G (green), and B (blue) define a single point incolor space. In 3D geometrics (and in 2D geometrics as well), matrices can be used to transform the position of a point, and, more imp
(图片来源:www.couleur.org)
A color matrix works the same way in color space. With a color matrix, you can change on
For technical reasons, points in 3D space are transformed with 4x4 matrices. A color in RGB color space can also be transformed with a 4x4 matrix. But as GDI+ works with a fourth 'color', A (alpha, or opacity) throughout, ColorMatrix is defined as a 5x5 matrix of REALs: typedef struct { REAL m[5][5]; } ColorMatrix;
GDI+ 提供用于存储和操作图像的 Image 和 Bitmap 类。Image 和 Bitmap 对象将每个像素的颜色都存储为 32 位的数:红色、绿色、蓝色和 alpha 各占 8 位。这四个分量的值都是 0 到 255,其中 0 表示没有亮度,255 表示最大亮度。alpha 分量指定颜色的透明度:0 表示完全透明,255 表示完全不透明。
颜色矢量采用 4 元组形式(红色、绿色、蓝色、alpha)。例如,颜色矢量 (0, 255, 0, 255) 表示一种没有红色和蓝色但绿色达到最大亮度的不透明颜色。
表示颜色的另一种惯例是用数字 1 表示亮度达到最大。使用这种惯例,上一段中描述的颜色将用 (0, 1, 0, 1) 表示。GDI+ 在进行颜色变换时使用以 1 表示最大亮度的惯例。
可通过用 4×4 矩阵乘以这些颜色矢量将线性变换(旋转和缩放等)应用到颜色矢量中。但是,您不能使用 4×4 矩阵进行平移(非线性)。如果在每个颜色矢量中再添加一个虚拟的第 5 坐标(例如,数字 1),则可使用 5×5 矩阵应用任何组合形式的线性变换和平移。由线性变换组成的后跟平移的变换称为仿射变换。
一言而蔽之,ColorMatrix是通过5 * 5矩阵对图像颜色(包括Alpha)进行的几何变换,理解和掌握ColorMatrix变换,能使你的图像产生千变万化的效果。
.NET中有个tem.Drawing.Imaging.ColorMatrix类,专门处理ColorMatrix相关的工作。MSDN对其解释为“定义包含 RGBA 空间坐标的 5 x 5 矩阵。ImageAttributes 类的若干方法通过使用颜色矩阵调整图像颜色”,“矩阵系数组成一个 5 x 5 的线性转换,用于转换 ARGB 单色值。例如,ARGB 向量表示为 Alpha、Red(红色)、Green(绿色)、Blue(蓝色)和 W,此处 W 始终为 1”。
具体的应用可以参考MSDN中对图像重新着色的相关文章:
讨论使用颜色矩阵变换颜色。
如何:转换图像颜色演示如何使用颜色矩阵转换颜色。
使用转换来调整颜色解释如何使用颜色矩阵调整颜色。
如何:旋转颜色描述如何使用颜色矩阵旋转颜色。
如何:修剪颜色定义剪切并解释如何使用颜色矩阵剪切颜色。
如何:使用颜色重新映射表定义重新映射并演示如何使用颜色重新映射表。
参考:
《对图像重新着色》
《ColorMatrix Basics - Simple Image Color Adjustment》
《Color Transformations and the Color Matrix》