国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

有關圖形方面的一篇文章,不妨一看

2024-07-21 02:23:54
字體:
來源:轉載
供稿:網友
working with brushes in gdi+

drawing gdi+ objects


the following code draws a line, an ellipse, a curve, and a polygon object. as you can see from the code, i抳e used pen object to fill these objects. see more details.

protected override void onpaint(painteventargs e)
{
      graphics g = e.graphics;
      pen pn = new pen(color.green, 10);
      g.drawline(pn, 100, 10, 30, 10);
      g.drawellipse( new pen(color.red, 20), 20, 40, 20, 20);
      g.drawbezier( new pen(color.blue, 5), new point(50,60), new      
point(150,10), new point(200,230), new point(100,100) );          
       pointf point1 = new pointf(50.0f, 250.0f);                  
      pointf point2 = new pointf(100.0f, 25.0f);
      pointf point3 = new pointf(150.0f, 5.0f);
      pointf point4 = new pointf(250.0f, 50.0f);
      pointf point5 = new pointf(300.0f, 100.0f);

     pointf[] curvepoints = {point1, point2, point3, point4, point5 };
      g.drawpolygon(new pen(color.chocolate, 10), curvepoints);
}
  

brush and brushes types  


brush type is an abstract base class. hatchbrush, lineargradientbrush, pathgradientbrush, solidbrush and texturebrush classes are inherited from brush class. you don抰 use this class directly.
all brush types are defined in system.drawing and its helper namespaces. before using brushes, you need to add reference to this namespace. hatchbrush and gradientbrush are defined in system.drawing.drawing2d namespace.
you use brushes to fill gdi+ objects with certain kind of brush. you generally call fill methods of graphics class to fill various objects such as ellipse, arc, or polygon. there are different kinds of brushes. for example, solid brush, hatch brush, texture brush, and gradient brush.

solid brushes


solid brushes are normal brushes with no style. you fill gdi+ object with a color. solidbrush type is used to work with solid brushes.

graphics g = e.graphics;                                    
solidbrush sdbrush1 = new solidbrush(color.red);                  
solidbrush sdbrush2 = new solidbrush(color.green);         
solidbrush sdbrush3 = new solidbrush(color.blue);    
g.fillellipse(sdbrush2, 20, 40, 60, 70);              
rectangle rect = new rectangle(0, 0, 200, 100);            
g.fillpie(sdbrush3, 0, 0, 200, 40, 0.0f, 30.0f );                 
pointf point1 = new pointf(50.0f, 250.0f);                       
pointf point2 = new pointf(100.0f, 25.0f);                  
pointf point3 = new pointf(150.0f, 40.0f);                  
pointf point4 = new pointf(250.0f, 50.0f);                  
pointf point5 = new pointf(300.0f, 100.0f);                             
pointf[] curvepoints = {point1, point2, point3, point4, point5 };    g.fillpolygon(sdbrush1, curvepoints);
the following code draws an ellipse, a pie, and a polygon.

hatch brushes


using system.drawing.drawing2d;
the hatch brushes are brushes with a hatch style, a foreground color, and a background color. hatches are a combination of rectangle lines and the area between the lines. the foreground color defines the color of lines; the background color defines the color of area between lines.
hatchstyle defines the hatch styles.

member name
backwarddiagonal
cross
darkdownwarddiagonal
darkhorizontal
darkupwarddiagonal
darkvertical
dasheddownwarddiagonal
dashedhorizontal
dashedupwarddiagonal
dashedvertical
diagonalbrick
diagonalcross
divot
dotteddiamond
dottedgrid
forwarddiagonal
the following code shows how to draw hatch brushes.


protected override void onpaint(painteventargs e)
{
      graphics g = e.graphics;
      hatchbrush hbrush1 = new hatchbrush(hatchstyle.diagonalcross, color.chocolate, color.red);
      hatchbrush hbrush2 = new hatchbrush(hatchstyle.dashedhorizontal, color.green, color.black);
      hatchbrush hbrush3 = new hatchbrush(hatchstyle.weave, color.blueviolet, color.blue);
      g.fillellipse(hbrush1, 20, 80, 60, 20);
      rectangle rect = new rectangle(0, 0, 200, 100);
      g.fillpie(hbrush3, 0, 0, 200, 40, 0.0f, 30.0f );
      pointf point1 = new pointf(50.0f, 250.0f);                  
      pointf point2 = new pointf(100.0f, 25.0f);
      pointf point3 = new pointf(150.0f, 40.0f);
      pointf point4 = new pointf(250.0f, 50.0f);
      pointf point5 = new pointf(300.0f, 100.0f);
  
      pointf[] curvepoints = {point1, point2, point3, point4, point5 };
      g.fillpolygon(hbrush2, curvepoints);
}
  
and the result looks like following -

texture brushes


the texture brushes provides you to use an image as brush and fill gdi+ objects with the brush. the following code use 搈yfile.bmp?as a brush. you need to define an image object and create brush with that image and pass the brush into fill method of gdi+ objects.

private brush txbrush;

protected override void onpaint(painteventargs e)
{
      graphics g = e.graphics;      
      g.fillrectangle(txbrush, clientrectangle);
}
private void form1_load(object sender, system.eventargs e)
{
      image img = new bitmap(@"c:/myfile.bmp");
      txbrush = new texturebrush(img);
}
the result looks like following:

gradient brushes


gradient brushes are provides more color to your gdi+ objects. by using lineargradientbrush type, you can blend two colors together. the following code blends red and green colors.

protected override void onpaint(painteventargs e)
{
      graphics g = e.graphics ;   
      rectangle rect = new rectangle(50, 30, 200, 200);   
      lineargradientbrush lbrush = new lineargradientbrush(rect, color.red, color.green,lineargradientmode.backwarddiagonal);  
      g.fillrectangle(lbrush, rect);
}
and the result looks like the following:
this like combines blue and green colors -   

lineargradientbrush lbrush = new lineargradientbrush(rect, color.blue, color.green, lineargradientmode.vertical);
and the result looks like following:  
菜鳥學堂:
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 勃利县| 红河县| 乡宁县| 金坛市| 昌吉市| 娄烦县| 恭城| 胶南市| 固阳县| 龙泉市| 隆安县| 罗江县| 临泽县| 武宁县| 涡阳县| 湖州市| 大洼县| 潞西市| 上饶县| 镇沅| 琼结县| 磐石市| 察隅县| 元谋县| 瓦房店市| 阳春市| 德钦县| 高唐县| 孝昌县| 神木县| 营山县| 津市市| 会理县| 永州市| 五河县| 黎平县| 称多县| 温宿县| 姜堰市| 甘孜县| 潼南县|