Csharp/C Sharp/2D Graphics/ImageAttributes — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:39, 26 мая 2010
Create an ImageAttributes object and set its color matrix
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
Bitmap bmp = new Bitmap("rama.jpg");
g.FillRectangle(Brushes.White, this.ClientRectangle);
for (int i = 1; i <= 7; ++i) {
Rectangle r = new Rectangle(i * 40 - 15, 0, 15, this.ClientRectangle.Height);
g.FillRectangle(Brushes.Gray, r);
}
float[][] matrixItems = {
new float[] {1, 0, 0, 03, 0},
new float[] {0, 1, 0, 0.1f, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 0.6f, 0},
new float[] {0, 0, 0, 0, 1}};
ColorMatrix colorMatrix = new ColorMatrix(matrixItems);
ImageAttributes imageAtt = new ImageAttributes();
imageAtt.SetColorMatrix(
colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
g.DrawImage(
bmp,
this.ClientRectangle, // destination rectangle
0.0f, // source rectangle x
0.0f, // source rectangle y
bmp.Width, // source rectangle width
bmp.Height, // source rectangle height
GraphicsUnit.Pixel,
imageAtt);
imageAtt.Dispose();
}
public static void Main() {
Application.Run(new Form1());
}
}