日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

ColorMatrix 彩色矩阵

發(fā)布時(shí)間:2023/11/27 生活经验 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ColorMatrix 彩色矩阵 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
選擇自 hbzxf 的 Blog

首先對裝配腦袋給出上兩片文章的友好回復(fù),還有網(wǎng)友Fisherman一起探討ColorMatrix話題表示感謝!

ColorMatrix (彩色矩陣) 類位于System.Drawing.Imaging命名空間 先看看下面的代碼

ColorMatrix?cm?=?new?ColorMatrix(new?float[][]{???new?float[]{0.5f,0.5f,0.5f,0,0},
????
new?float[]{0.5f,0.5f,0.5f,0,0},
????
new?float[]{0.5f,0.5f,0.5f,0,0},
????
new?float[]{0,0,0,1,0,0},
????
new?float[]{0,0,0,0,1,0},
????
new?float[]{0,0,0,0,0,1}}
);

矩陣系數(shù)組成一個(gè) 5x5 的線性轉(zhuǎn)換,用于轉(zhuǎn)換 ARGB 的單色值。例如,ARGB 向量表示為 Alpha、Red(紅色)、Green(綠色)、Blue(藍(lán)色)和 W,此處 W 始終為 1。

那么w是什么?為什么要定義為5x5的矩陣呢?

經(jīng)過查找MSDN發(fā)現(xiàn)有這篇文章 《使用顏色矩陣對單色進(jìn)行變換》里面這樣講到:

GDI+ 提供用于存儲(chǔ)和操作圖像的 ImageBitmap 類。ImageBitmap 對象將每個(gè)像素的顏色都存儲(chǔ)為 32 位的數(shù):紅色、綠色、藍(lán)色和 alpha 各占 8 位。這四個(gè)分量的值都是 0 到 255,其中 0 表示沒有亮度,255 表示最大亮度。alpha 分量指定顏色的透明度:0 表示完全透明,255 表示完全不透明。

顏色矢量采用 4 元組形式(紅色、綠色、藍(lán)色、alpha)。例如,顏色矢量 (0, 255, 0, 255) 表示一種沒有紅色和藍(lán)色但綠色達(dá)到最大亮度的不透明顏色。

表示顏色的另一種慣例是用數(shù)字 1 表示亮度達(dá)到最大。使用這種慣例,上一段中描述的顏色將用 (0, 1, 0, 1) 表示。GDI+ 在進(jìn)行顏色變換時(shí)使用以 1 表示最大亮度的慣例。

可通過用 4×4 矩陣乘以這些顏色矢量將線性變換(旋轉(zhuǎn)和縮放等)應(yīng)用到顏色矢量中。但是,您不能使用 4×4 矩陣進(jìn)行平移(非線性)。如果在每個(gè)顏色矢量中再添加一個(gè)虛擬的第 5 坐標(biāo)(例如,數(shù)字 1),則可使用 5×5 矩陣應(yīng)用任何組合形式的線性變換和平移。由線性變換組成的后跟平移的變換稱為仿射變換。

我認(rèn)為可以理解為虛擬向量


在Visual C#下實(shí)現(xiàn)圖像的透明處理 這篇文章寫得不錯(cuò)建議看看
?地址:
http://tech.ccidnet.com/pub/article/c294_a36258_p1.html

彩色矩陣應(yīng)用到圖像上可以使用ImageAttributes.SetColorMatrix 方法

[C#]

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace GrayShear
{/// <summary>/// Summary description for Form1./// </summary>public class Form1 : System.Windows.Forms.Form{/// <summary>/// Required designer variable./// </summary>private System.ComponentModel.Container components = null;
    public Form1(){//// Required for Windows Form Designer support//InitializeComponent();
      //// TODO: Add any constructor code after InitializeComponent call//}
    /// <summary>/// Clean up any resources being used./// </summary>protected override void Dispose( bool disposing ){if( disposing ){if (components != null) {components.Dispose();}}base.Dispose( disposing );}
    #region Windows Form Designer generated code/// <summary>/// Required method for Designer support - do not modify/// the contents of this method with the code editor./// </summary>private void InitializeComponent(){// // Form1// this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);this.ClientSize = new System.Drawing.Size(296, 269);this.Name = "Form1";this.Text = "Form1";this.Load += new System.EventHandler(this.Form1_Load);
    }#endregion
    /// <summary>/// The main entry point for the application./// </summary>[STAThread]static void Main() {Application.Run(new Form1());}
    private void Form1_Load(object sender, System.EventArgs e){OpenFileDialog dlg = new OpenFileDialog();dlg.Filter="Image files (*.BMP, *.JPG, *.GIF)|*.bmp;*.jpg;*.gif";if(dlg.ShowDialog()==DialogResult.OK){Image img = Image.FromFile(dlg.FileName);Bitmap bm = new Bitmap(img.Width,img.Height);Graphics g = Graphics.FromImage(bm);
?
        ColorMatrix cm = new ColorMatrix(new float[][]{   new float[]{0.5f,0.5f,0.5f,0,0},new float[]{0.5f,0.5f,0.5f,0,0},new float[]{0.5f,0.5f,0.5f,0,0},new float[]{0,0,0,1,0,0},new float[]{0,0,0,0,1,0},new float[]{0,0,0,0,0,1}});
        
        /*
        //Gilles Khouzams colour corrected grayscale shearColorMatrix cm = new ColorMatrix(new float[][]{   new float[]{0.3f,0.3f,0.3f,0,0},new float[]{0.59f,0.59f,0.59f,0,0},new float[]{0.11f,0.11f,0.11f,0,0},new float[]{0,0,0,1,0,0},new float[]{0,0,0,0,1,0},new float[]{0,0,0,0,0,1}});
        */

        ImageAttributes ia = new ImageAttributes();ia.SetColorMatrix(cm);g.DrawImage(img,new Rectangle(0,0,img.Width,img.Height),0,0,img.Width,img.Height,GraphicsUnit.Pixel,ia);g.Dispose();this.BackgroundImage=bm;}  }}


}

總結(jié)

以上是生活随笔為你收集整理的ColorMatrix 彩色矩阵的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。