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

首頁 > 學院 > 開發設計 > 正文

C#用自定義或指定顏色填充矩形

2019-11-17 03:48:34
字體:
來源:轉載
供稿:網友

用到某處要使用自定義顏色填充圖像,貌似Graphics.FillRectangle方法只能用Brush來填充。但是常規Brush都是Brushes定義好的Brush,怎么辦呢?

GOOGLE了下有兩種方法:
一、用新SolidBrush填充
 

public void FillByColor(Rectangle rect,Color c,Graphics G){    G.FillRectangle(new SolidBrush(c), rect);}

 

參考文章:《如何:創建線性漸變》

 

二、用API實現指定顏色填充一個閉合區域(未測試)
用API實現指定顏色填充
using System.Runtime.InteropServices;[DllImport("gdi32.dll")]public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);[DllImport("gdi32.dll")]public static extern IntPtr CreateSolidBrush(int crColor);[DllImport("gdi32.dll")]public static extern bool ExtFloodFill(IntPtr hdc, int nXStart, int nYStart, int crColor, uint fuFillType);[DllImport("gdi32.dll")]public static extern bool DeleteObject(IntPtr hObject);[DllImport("gdi32.dll")]public static extern int GetPixel(IntPtr hdc, int x, int y);public static uint FLOODFILLBORDER = 0;public static uint FLOODFILLSURFACE = 1;PRivate void button1_Click(object sender, EventArgs e){    Graphics vGraphics = Graphics.FromHwnd(Handle);    vGraphics.DrawRectangle(Pens.Blue, new Rectangle(0, 0, 300, 300));    vGraphics.DrawRectangle(Pens.Blue, new Rectangle(50, 70, 300, 300));    IntPtr vDC = vGraphics.GetHdc();    IntPtr vBrush = CreateSolidBrush(ColorTranslator.ToWin32(Color.Red));    IntPtr vPreviouseBrush = SelectObject(vDC, vBrush);    ExtFloodFill(vDC, 10, 10, GetPixel(vDC, 10, 10), FLOODFILLSURFACE);    SelectObject(vDC, vPreviouseBrush);    DeleteObject(vBrush);    vGraphics.ReleaseHdc(vDC);}
 

參考文章:http://www.csharpwin.com/csharpspace/9115r3566.shtml
 

 

(本文來源:http://www.survivalescaperooms.com/allanswolf/archive/2010/04/22/1718217.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 梓潼县| 理塘县| 望谟县| 昭通市| 东丽区| 班玛县| 微博| 奉节县| 原阳县| 奇台县| 普洱| 诸暨市| 凤山县| 信阳市| 莫力| 米林县| 开封市| 浏阳市| 饶平县| 玉山县| 家居| 康定县| 乐陵市| 历史| 巫山县| 嘉善县| 武胜县| 西畴县| 博湖县| 山西省| 旬阳县| 军事| 虎林市| 南宫市| 万源市| 巨鹿县| 分宜县| 高台县| 噶尔县| 天祝| 孙吴县|