当前位置: 首页>>代码示例>>C#>>正文


C# ColorMatrix类代码示例

本文整理汇总了C#中System.Drawing.Imaging.ColorMatrix的典型用法代码示例。如果您正苦于以下问题:C# ColorMatrix类的具体用法?C# ColorMatrix怎么用?C# ColorMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ColorMatrix类属于System.Drawing.Imaging命名空间,在下文中一共展示了ColorMatrix类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Bitmap

Image image = new Bitmap("InputColor.bmp");
ImageAttributes imageAttributes = new ImageAttributes();
int width = image.Width;
int height = image.Height;

float[][] colorMatrixElements = { 
   new float[] {2,  0,  0,  0, 0},        // red scaling factor of 2
   new float[] {0,  1,  0,  0, 0},        // green scaling factor of 1
   new float[] {0,  0,  1,  0, 0},        // blue scaling factor of 1
   new float[] {0,  0,  0,  1, 0},        // alpha scaling factor of 1
   new float[] {.2f, .2f, .2f, 0, 1}};    // three translations of 0.2

ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);

imageAttributes.SetColorMatrix(
   colorMatrix,
   ColorMatrixFlag.Default,
   ColorAdjustType.Bitmap);

e.Graphics.DrawImage(image, 10, 10);

e.Graphics.DrawImage(
   image,
   new Rectangle(120, 10, width, height),  // destination rectangle 
   0, 0,        // upper-left corner of source rectangle 
   width,       // width of source rectangle
   height,      // height of source rectangle
   GraphicsUnit.Pixel,
   imageAttributes);
开发者ID:.NET开发者,项目名称:System.Drawing.Imaging,代码行数:29,代码来源:ColorMatrix

示例2: new ColorMatrix(matrixItems)

//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Drawing.Printing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {

    protected override void OnPaint(PaintEventArgs e) {
        Bitmap bmp = new Bitmap("alphabet.gif");
        Graphics g = e.Graphics;

        float[][] matrixItems = {
                    new float[] {0.2f, 0, 0, 0, 0},
                    new float[] {0, 0.8f, 0, 0, 0},
                    new float[] {0, 0, 1, 0, 0},
                    new float[] {0, 0, 0, 1, 0}, 
                    new float[] {0, 0, 0, 0, 1}};
        ColorMatrix colorMatrix = new ColorMatrix(matrixItems);

        ImageAttributes imageAtt = new ImageAttributes();
        imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

        TextureBrush tb = new TextureBrush(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), imageAtt);
        tb.WrapMode = WrapMode.Tile;
        g.FillRectangle(tb, this.ClientRectangle);
        bmp.Dispose();
        tb.Dispose();
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}
开发者ID:C#程序员,项目名称:System.Drawing.Imaging,代码行数:40,代码来源:ColorMatrix


注:本文中的System.Drawing.Imaging.ColorMatrix类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。