文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学的各位小编整理了ASP.net-基于VC.NET的GDI+编程入门之画刷的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
基于线条的、封闭的图形需要画笔来表现,封闭的形状的典型的特点在于它可以用图形、颜色或模式来填充。private: System::Void Form1_Paint(System::Object * sender,PaintEventArgs * e) { e->Graphics->FillRectangle(SomeBrush, 20, 20, 200, 160); } |
public: SolidBrush(Color color); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { SolidBrush *brushBlue = new SolidBrush(Color::Blue); e->Graphics->FillRectangle(brushBlue, 20, 20, 200, 160); } |
图一、代码运行效果图 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { SolidBrush *colorizer = new SolidBrush(Color::Lime); e->Graphics->FillRectangle(colorizer, 10, 10, 120, 120); colorizer->Color = Color::Salmon; e->Graphics->FillRectangle(colorizer, 140, 10, 120, 120); colorizer->Color = Color::Aqua; e->Graphics->FillRectangle(colorizer, 10, 140, 120, 120); colorizer->Color = Color::Navy; e->Graphics->FillRectangle(colorizer, 140, 140, 120, 120); } |
图二、代码运行效果图 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { SolidBrush *colorizer = new SolidBrush(Color::Lime); e->Graphics->FillRectangle(colorizer, 10, 10, 120, 120); colorizer->Color = Color::Salmon; e->Graphics->FillRectangle(colorizer, 140, 10, 120, 120); colorizer->Color = Color::Aqua; e->Graphics->FillRectangle(colorizer, 10, 140, 120, 120); colorizer->Color = Color::Navy; e->Graphics->FillRectangle(colorizer, 140, 140, 120, 120); colorizer.Dispose(); } |
public: HatchBrush(HatchStyle style, Color foreColor); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { using namespace System::Drawing::Drawing2D; HatchBrush *brushBackDiag = new HatchBrush(HatchStyle::BackwardDiagonal, Color::FromArgb(0, 0, 255)); HatchBrush *brushCross = new HatchBrush(HatchStyle::Cross, Color::FromArgb(200, 0, 0)); HatchBrush *brushDarkDown = new HatchBrush(HatchStyle::DarkDownwardDiagonal, Color::Salmon); HatchBrush *brushDarkHorz = new HatchBrush(HatchStyle::DarkHorizontal, Color::Navy); HatchBrush *brushDarkUpDiag = new HatchBrush(HatchStyle::DarkUpwardDiagonal, Color::Pink); HatchBrush *brushVertical = new HatchBrush(HatchStyle::DarkVertical, Color::FromArgb(255, 0, 255)); HatchBrush *brushDashDnDiag = new HatchBrush( HatchStyle::DashedDownwardDiagonal, Color::FromArgb(255, 128, 0)); HatchBrush *brushDashHorz = new HatchBrush(HatchStyle::DashedHorizontal, Color::FromArgb(0, 128, 192)); HatchBrush *brushDashUpDiag = new HatchBrush(HatchStyle::DashedUpwardDiagonal, Color::Green); HatchBrush *brushDashVert = new HatchBrush(HatchStyle::DashedVertical, Color::Firebrick); HatchBrush *brushDiagBrisk = new HatchBrush(HatchStyle::DiagonalBrick, Color::Fuchsia); HatchBrush *brushDiagCross = new HatchBrush(HatchStyle::DiagonalCross, Color::Moccasin); HatchBrush *brushDivot = new HatchBrush(HatchStyle::Divot, Color::Goldenrod); HatchBrush *brushDotDiamond = new HatchBrush(HatchStyle::DottedDiamond, Color::Gainsboro); HatchBrush *brushDottedGrid = new HatchBrush(HatchStyle::DottedGrid, Color::Khaki); HatchBrush *brushForDiag = new HatchBrush(HatchStyle::ForwardDiagonal, Color::Maroon); HatchBrush *brushHorz = new HatchBrush(HatchStyle::Horizontal, Color::Red); HatchBrush *brushHorzBrick = new HatchBrush(HatchStyle::HorizontalBrick, Color::SaddleBrown); HatchBrush *brushLgChkBoard = new HatchBrush(HatchStyle::LargeCheckerBoard, Color::RoyalBlue); HatchBrush *brushLgConfetti = new HatchBrush(HatchStyle::LargeConfetti, Color::MistyRose); HatchBrush *brushLgGrid = new HatchBrush(HatchStyle::LargeGrid, Color::Purple); HatchBrush *brushLtDnDiag = new HatchBrush( HatchStyle::LightDownwardDiagonal, Color::DarkCyan); HatchBrush *brushLtHorz = new HatchBrush(HatchStyle::LightHorizontal, Color::PowderBlue); HatchBrush *brushUpDiag = new HatchBrush( HatchStyle::LightUpwardDiagonal, Color::SeaGreen); HatchBrush *brushLtVert = new HatchBrush(HatchStyle::LightVertical, Color::Olive); e->Graphics->FillRectangle(brushBackDiag, 20, 20, 80, 60); e->Graphics->FillRectangle(brushCross, 120, 20, 80, 60); e->Graphics->FillRectangle(brushDarkDown, 220, 20, 80, 60); e->Graphics->FillRectangle(brushDarkHorz, 320, 20, 80, 60); e->Graphics->FillRectangle(brushDarkUpDiag, 420, 20, 80, 60); e->Graphics->FillRectangle(brushVertical, 20, 100, 80, 60); e->Graphics->FillRectangle(brushDashDnDiag, 120, 100, 80, 60); e->Graphics->FillRectangle(brushDashHorz, 220, 100, 80, 60); e->Graphics->FillRectangle(brushDashUpDiag, 320, 100, 80, 60); e->Graphics->FillRectangle(brushDashVert, 420, 100, 80, 60); e->Graphics->FillRectangle(brushDashVert, 20, 180, 80, 60); e->Graphics->FillRectangle(brushDiagBrisk, 120, 180, 80, 60); e->Graphics->FillRectangle(brushDiagCross, 220, 180, 80, 60); e->Graphics->FillRectangle(brushDivot, 320, 180, 80, 60); e->Graphics->FillRectangle(brushDotDiamond, 420, 180, 80, 60); e->Graphics->FillRectangle(brushDottedGrid, 20, 260, 80, 60); e->Graphics->FillRectangle(brushForDiag, 120, 260, 80, 60); e->Graphics->FillRectangle(brushHorz, 220, 260, 80, 60); e->Graphics->FillRectangle(brushHorzBrick, 320, 260, 80, 60); e->Graphics->FillRectangle(brushLgChkBoard, 420, 260, 80, 60); e->Graphics->FillRectangle(brushLgGrid, 20, 340, 80, 60); e->Graphics->FillRectangle(brushLtDnDiag, 120, 340, 80, 60); e->Graphics->FillRectangle(brushLtHorz, 220, 340, 80, 60); e->Graphics->FillRectangle(brushUpDiag, 320, 340, 80, 60); e->Graphics->FillRectangle(brushLtVert, 420, 340, 80, 60); } |
图三、各种网络格画刷效果图 |
public: HatchBrush(HatchStyle hatchstyle, Color foreColor, Color backColor); |
图四、位图效果图 |
public: TextureBrush(Image *bitmap); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Bitmap *bmpPapers = new Bitmap(S"Papers.bmp"); TextureBrush *brushPapers = new TextureBrush(bmpPapers); e->Graphics->FillRectangle(brushPapers, 5, 5, 430, 280); } |
图五、代码运行效果图 |
public: TextureBrush(Image *bitmap, Rectangle destination); |
public: TextureBrush(Image *bitmap, RectangleF destination); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Bitmap *bmpPapers = new Bitmap(S"Papers.bmp"); TextureBrush *brushPapers = new TextureBrush(bmpPapers, new Rectangle(0, 0, 40, 42)); e->Graphics->FillRectangle(brushPapers, 5, 5, 438, 290); } |
图六、代码运行效果图 |
public: TextureBrush(Image *bitmap, WrapMode wrapMode); public: TextureBrush(Image *bitmap, WrapMode wrapMode, Rectangle destination); public: TextureBrush(Image *bitmap, WrapMode wrapMode, RectangleF destination); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Bitmap *bmpPapers = new Bitmap(S"Papers.bmp"); TextureBrush *brushPapers = new TextureBrush(bmpPapers, WrapMode::Clamp); e->Graphics->FillRectangle(brushPapers, 5, 5, 438, 290); } |
图七、Clamp方式效果图 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Bitmap *bmpPapers = new Bitmap(S"Papers.bmp"); TextureBrush *brushPapers = new TextureBrush(bmpPapers, WrapMode::Tile, Rectangle(0, 0, 40, 42)); e->Graphics->FillRectangle(brushPapers, 5, 5, 438, 290); } |
图八、Tile方式效果图 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Bitmap *bmpPapers = new Bitmap(S"Papers.bmp"); TextureBrush *brushPapers = new TextureBrush(bmpPapers, WrapMode::TileFlipX); e->Graphics->FillRectangle(brushPapers, 5, 5, 430, 290); } |
图九、TileFlipX方式效果图 |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Bitmap *bmpPapers = new Bitmap(S"Papers.bmp"); TextureBrush *brushPapers = new TextureBrush(bmpPapers, WrapMode.TileFlipXY, Rectangle(0, 0, 42, 42)); e->Graphics->FillRectangle(brushPapers, 5, 5, 412, 244); } |
图十、TileFlipXY方式效果图 |
public: LinearGradientBrush(Point point1, Point point2, Color color1, Color color2); public: LinearGradientBrush(PointF point1, PointF point2, Color color1, Color color2); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { using namespace System::Drawing::Drawing2D; LinearGradientBrush *lgb = new LinearGradientBrush(Point(20, 20), Point(450,20), Color::DarkGreen, Color::LightBlue); e->Graphics->FillRectangle(lgb, 20, 20, 430, 180); } |
图十一、线性渐变画刷效果 |
public: LinearGradientBrush(Rectangle rect, Color color1, Color color2, LinearGradientMode factor); public: LinearGradientBrush(RectangleF rect, Color color1, Color color2, LinearGradientMode factor); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { using namespace System::Drawing::Drawing2D; Rectangle rect(10, 10, 470, 300); LinearGradientBrush *lgb = new LinearGradientBrush(rect, Color::DarkRed,Color::White, LinearGradientMode::Vertical); e->Graphics->FillRectangle(lgb, 10, 10, 450, 280); } |
图十二、代码运行效果图 |
public: LinearGradientBrush(Rectangle rect, Color color1, Color color2, float angle); public: LinearGradientBrush(RectangleF rect, Color color1, Color color2, float angle); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { using namespace System::Drawing::Drawing2D; Rectangle rect(10, 10, 470, 300); LinearGradientBrush *lgb = new LinearGradientBrush(rect, Color::DarkRed, Color::White, -65.24F); e->Graphics->FillRectangle(lgb, 10, 10, 450, 280); } |
图十三、代码运行效果图 |
public: PathGradientBrush(Point points[]); public: PathGradientBrush(PointF points[]); |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { using namespace System::Drawing::Drawing2D; Point ptGraph[] = { Point(10, 10), Point(450, 10), Point(450, 250), Point(10, 250) }; PathGradientBrush *pgb = new PathGradientBrush(ptGraph); e->Graphics->FillRectangle(pgb, 10, 10, 450, 280); } |
图十四、代码运行效果图 |