我如何减慢此填充算法,以便用户可以逐渐填充图像?
我尝试使用sleep()
与redraw()
结合使用,但这会导致程序崩溃。 flood_fineded
消息导致调用redraw()
void Redraw()
{
InvalidateRect(g_hWnd, NULL, FALSE);
UpdateWindow(g_hWnd);
}
void FloodFillUtil(CDIB32* scr, int xPos, int yPos)
{
//using namespace std::chrono_literals;
if (IsValid(scr, xPos, yPos))
{
//Redraw();
scr->SetRGB(xPos, yPos, 255, 0, 0);
FloodFillUtil(scr, xPos + 1, yPos);
FloodFillUtil(scr, xPos - 1, yPos);
FloodFillUtil(scr, xPos, yPos + 1);
FloodFillUtil(scr, xPos, yPos - 1);
}
return;
}
void FloodFill(CDIB32* scr, CPoint& mid)
{
int xPos = mid.x;
int yPos = mid.y;
FloodFillUtil(scr, xPos, yPos);
}
void SetupDoItThread()
{
std::thread Worker(DoIt);
Worker.join();
}
void SetupDogThreads(CPoint mid)
{
//Redraw();
FloodFill(&m_screenDib, mid);
}
void DoIt()
{
if (!m_done)
{
CPoint mid;
std::vector<std::thread> threads;
for (int i = 0; i < REZ * REZ; ++i)
{
CPoint mid;
GetBlobMidPoint(i, mid);
threads.push_back(std::thread(SetupDogThreads, mid));
}
for (auto& th : threads)
{
th.join();
}
::PostMessage(g_hWnd, FLOOD_FINISHED, NULL, NULL);
m_done = true;
}
}
I have tried to use sleep()
in conjunction with Redraw()
but this causes the program to crash. The FLOOD_FINISHED
message causes a call to Redraw()
void Redraw()
{
InvalidateRect(g_hWnd, NULL, FALSE);
UpdateWindow(g_hWnd);
}
void FloodFillUtil(CDIB32* scr, int xPos, int yPos)
{
//using namespace std::chrono_literals;
if (IsValid(scr, xPos, yPos))
{
//Redraw();
scr->SetRGB(xPos, yPos, 255, 0, 0);
FloodFillUtil(scr, xPos + 1, yPos);
FloodFillUtil(scr, xPos - 1, yPos);
FloodFillUtil(scr, xPos, yPos + 1);
FloodFillUtil(scr, xPos, yPos - 1);
}
return;
}
void FloodFill(CDIB32* scr, CPoint& mid)
{
int xPos = mid.x;
int yPos = mid.y;
FloodFillUtil(scr, xPos, yPos);
}
void SetupDoItThread()
{
std::thread Worker(DoIt);
Worker.join();
}
void SetupDogThreads(CPoint mid)
{
//Redraw();
FloodFill(&m_screenDib, mid);
}
void DoIt()
{
if (!m_done)
{
CPoint mid;
std::vector<std::thread> threads;
for (int i = 0; i < REZ * REZ; ++i)
{
CPoint mid;
GetBlobMidPoint(i, mid);
threads.push_back(std::thread(SetupDogThreads, mid));
}
for (auto& th : threads)
{
th.join();
}
::PostMessage(g_hWnd, FLOOD_FINISHED, NULL, NULL);
m_done = true;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论