用指定颜色填充一个闭合区域
2007-05-22 21:47
399 查看
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);
}
[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);
}
相关文章推荐
- 使用floodfill()函数颜色填充一个联通的区域
- Matlab图像剪切,超出图像区域指定颜色填充
- 用指定颜色填充一个连接域
- OpenCV图像剪切,超出图像区域指定颜色填充
- FillConsoleOutputAttribute 函数--指定区域填充控制台输出属性
- 多分类问题中,实现不同分类区域颜色填充的MATLAB代码(demo:Random Forest)
- iOS 如何判断一个点在某个指定区域中
- 判断一个点是否在指定区域内
- javascript实现改变图片指定区域的颜色
- 如何在指定的内存区域 new 一个对象
- 用GDI+画图像,根据鼠标区域改变填充颜色
- 第四讲:使用html5中的canvas标签画出一个球在指定区域内的运动
- Android 绘制一个Loading动画__向图片中缓慢填充颜色,从而形成动画效果
- angularjs实现任意点击一个标签,指定的标签展开,其他的标签闭合
- 如何为不规则图形填充颜色 (注:图形是闭合的)
- 思绪膨胀,做出龙飞凤舞,怪诞异常的程序启动界面(VB6.0)[第二章:填充区域成不同的颜色,和用图片填充背景]
- Html5 Canvas开发之清除一个特定区域内的Canvas、宽高技巧、使Canvas填充整个浏览器窗口
- 如何判断一个指定的经纬度点是否落在一个多边形区域内?
- PHP - Manual手册 - CLXI. String 字符串处理函数 - str_pad使用另一个字符串将一个字符串填充到指定长度
- UIButton的resizableImageWithCapInsets使用解析--拉伸模式,通过拉伸UIEdgeInsets指定的矩形区域来填充图片