自定义画刷 Brushes与SolidBrush

Rectangle rect = new Rectangle(0, 0, 200, 200);

// Fill rectangle to screen.
 g.FillRectangle(Brushes.Red, rect);   //系统自带的画刷 

若要自定义颜色,则要用到SolidBrush

 

例子:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class test11 : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
    {
        FillRectangleRectangle();

    }

public void FillRectangleRectangle()
    {

        int height = 500, width = 700;
        Bitmap image = new Bitmap(width, height);
        //创建Graphics类对象
        Graphics g = Graphics.FromImage(image);
        // Create solid brush.
        ///SolidBrush blueBrush = new SolidBrush(Color.FromArgb(0xF1,0x2F,0xFF));

        //自定义画刷
        SolidBrush myBrush = new SolidBrush(System.Drawing.ColorTranslator.FromHtml("#ECECFF"));
        // Create rectangle.
        Rectangle rect = new Rectangle(0, 0, 200, 200);

        // Fill rectangle to screen.
        // g.FillRectangle(Brushes.Red, rect);   //系统自带的画刷
        g.FillRectangle(myBrush, rect);

        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        Response.ClearContent();
        Response.ContentType = "image/Jpeg";
        Response.BinaryWrite(ms.ToArray());
    }

}

你可能感兴趣的:(image,object,Class)