當前位置: 首頁>>代碼示例>>C#>>正文


C# ImageAttributes類代碼示例

本文整理匯總了C#中System.Drawing.Imaging.ImageAttributes的典型用法代碼示例。如果您正苦於以下問題:C# ImageAttributes類的具體用法?C# ImageAttributes怎麽用?C# ImageAttributes使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ImageAttributes類屬於System.Drawing.Imaging命名空間,在下文中一共展示了ImageAttributes類的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,代碼來源:ImageAttributes

示例2: new ImageAttributes()

//引入命名空間
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,代碼來源:ImageAttributes


注:本文中的System.Drawing.Imaging.ImageAttributes類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。