本文整理匯總了C#中System.Drawing.Imaging.ImageAttributes.SetColorMatrix方法的典型用法代碼示例。如果您正苦於以下問題:C# ImageAttributes.SetColorMatrix方法的具體用法?C# ImageAttributes.SetColorMatrix怎麽用?C# ImageAttributes.SetColorMatrix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Imaging.ImageAttributes
的用法示例。
在下文中一共展示了ImageAttributes.SetColorMatrix方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SetColorMatrixExample
private void SetColorMatrixExample(PaintEventArgs e)
{
// Create a rectangle image with all colors set to 128 (medium
// gray).
Bitmap myBitmap = new Bitmap(50, 50, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(myBitmap);
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 128, 128, 128)),
new Rectangle(0, 0, 50, 50));
myBitmap.Save("Rectangle1.jpg");
// Open an Image file and draw it to the screen.
Image myImage = Image.FromFile("Rectangle1.jpg");
e.Graphics.DrawImage(myImage, 20, 20);
// Initialize the color matrix.
ColorMatrix myColorMatrix = new ColorMatrix();
// Red
myColorMatrix.Matrix00 = 1.75f;
// Green
myColorMatrix.Matrix11 = 1.00f;
// Blue
myColorMatrix.Matrix22 = 1.00f;
// alpha
myColorMatrix.Matrix33 = 1.00f;
// w
myColorMatrix.Matrix44 = 1.00f;
// Create an ImageAttributes object and set the color matrix.
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetColorMatrix(myColorMatrix);
// Draw the image using the color matrix.
Rectangle rect = new Rectangle(100, 20, 200, 200);
e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200,
GraphicsUnit.Pixel, imageAttr);
}
示例2: RotateColors
private void RotateColors(PaintEventArgs e)
{
Bitmap image = new Bitmap("RotationInput.bmp");
ImageAttributes imageAttributes = new ImageAttributes();
int width = image.Width;
int height = image.Height;
float degrees = 60f;
double r = degrees * System.Math.PI / 180; // degrees to radians
float[][] colorMatrixElements = {
new float[] {(float)System.Math.Cos(r), (float)System.Math.Sin(r), 0, 0, 0},
new float[] {(float)-System.Math.Sin(r), (float)-System.Math.Cos(r), 0, 0, 0},
new float[] {0, 0, 2, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}};
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
e.Graphics.DrawImage(image, 10, 10, width, height);
e.Graphics.DrawImage(
image,
new Rectangle(150, 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);
}
示例3: OnPaint
//引入命名空間
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());
}
}