GDI色彩填充

zgke 2008-05-15 10:34:26
在.NET 1.1 里有没有 API里的FloodFill这个东西.
就是怎么像画板颜色填充那样.
...全文
63 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gomoku 2008-05-15
  • 打赏
  • 举报
回复
自己写也不难,这是我找到的vb代码,源自http://vb-helper.com/howto_net_unsafe_flood.html


' Flood fill the point.
Public Sub SafeFloodFill(ByVal bm As Bitmap, ByVal x As _
Integer, ByVal y As Integer, ByVal new_color As Color)
' Get the old and new colors.
Dim old_color As Color = bm.GetPixel(x, y)

' Start with the original point in the stack.
Dim pts As New Stack(1000)
pts.Push(New Point(x, y))
bm.SetPixel(x, y, new_color)

' While the stack is not empty, process a point.
Do While pts.Count > 0
Dim pt As Point = DirectCast(pts.Pop(), Point)
If pt.X > 0 Then SafeCheckPoint(bm, pts, pt.X - 1, _
pt.Y, old_color, new_color)
If pt.Y > 0 Then SafeCheckPoint(bm, pts, pt.X, pt.Y _
- 1, old_color, new_color)
If pt.X < bm.Width - 1 Then SafeCheckPoint(bm, pts, _
pt.X + 1, pt.Y, old_color, new_color)
If pt.Y < bm.Height - 1 Then SafeCheckPoint(bm, _
pts, pt.X, pt.Y + 1, old_color, new_color)
Loop
End Sub

' See if this point should be added to the stack.
Private Sub SafeCheckPoint(ByVal bm As Bitmap, ByVal pts As _
Stack, ByVal x As Integer, ByVal y As Integer, ByVal _
old_color As Color, ByVal new_color As Color)
Dim clr As Color = bm.GetPixel(x, y)
If clr.Equals(old_color) Then
pts.Push(New Point(x, y))
bm.SetPixel(x, y, new_color)
End If
End Sub


zgke 2008-05-15
  • 打赏
  • 举报
回复
或则别的什么办法解决啊

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧