使用 c-sharp 的 FloodFill
FloodFill using c-sharp
我正在尝试使用 C-sharp 重写一些旧的 vb6 代码。问题是,当我在 vb 中使用 FloodFill 时,它会保存具有 FloodFill 影响的图像。使用升 C 并非如此。这是 VB6 的代码段:
hTempBrush = CreateSolidBrush(&H400000)
'Select the brush into the dc.
hPrevBrush = SelectObject(Maparea.hdc, hTempBrush)
'Fill the area.
FloodFill Maparea.hdc, (100 ), (200), MapColor
SelectObject Maparea.hdc, hPrevBrush
DeleteObject hTempBrush
SavePicture Maparea.Picture, "filename.bmp" ' saves picture with flood fill affect
这里是 c#
Graphics g2 = Graphics.FromHwnd(pictureBox1.handle);
IntPtr vDC = g2.GetHdc();
IntPtr vBrush = CreateSolidBrush(ColorTranslator.ToWin32(Color.Navy));
IntPtr vPreviouseBrush = SelectObject(vDC, vBrush);
int hh = ColorTranslator.ToWin32(Color.Wheat);
FloodFill(vDC, 100, 200, hh);
SelectObject(vDC, vPreviouseBrush);
DeleteObject(vBrush);
pictureBox1.Image.Save("map.bmp"); // saves without the affect of floodfill
g2.ReleaseHdc(vDC);
感谢任何帮助。
我找到了答案。我必须使用 BitBlt,这样出现在控制面上的所有东西都会被保存。
private void button4_Click(object sender, EventArgs e)
{
var bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
using (var bmpGraphics = Graphics.FromImage(bmp))
{
var despDC = bmpGraphics.GetHdc();
using (Graphics formGraphics = Graphics.FromHwnd(pictureBox1.Handle))
{
var srcDC = formGraphics.GetHdc();
BitBlt(despDC, 0, 0, pictureBox1.Width, pictureBox1.Height, srcDC, 0, 0, SRCCOPY);
formGraphics.ReleaseHdc(srcDC);
}
bmpGraphics.ReleaseHdc(despDC);
}
bmp.Save("map1.jpg");
我正在尝试使用 C-sharp 重写一些旧的 vb6 代码。问题是,当我在 vb 中使用 FloodFill 时,它会保存具有 FloodFill 影响的图像。使用升 C 并非如此。这是 VB6 的代码段:
hTempBrush = CreateSolidBrush(&H400000)
'Select the brush into the dc.
hPrevBrush = SelectObject(Maparea.hdc, hTempBrush)
'Fill the area.
FloodFill Maparea.hdc, (100 ), (200), MapColor
SelectObject Maparea.hdc, hPrevBrush
DeleteObject hTempBrush
SavePicture Maparea.Picture, "filename.bmp" ' saves picture with flood fill affect
这里是 c#
Graphics g2 = Graphics.FromHwnd(pictureBox1.handle);
IntPtr vDC = g2.GetHdc();
IntPtr vBrush = CreateSolidBrush(ColorTranslator.ToWin32(Color.Navy));
IntPtr vPreviouseBrush = SelectObject(vDC, vBrush);
int hh = ColorTranslator.ToWin32(Color.Wheat);
FloodFill(vDC, 100, 200, hh);
SelectObject(vDC, vPreviouseBrush);
DeleteObject(vBrush);
pictureBox1.Image.Save("map.bmp"); // saves without the affect of floodfill
g2.ReleaseHdc(vDC);
感谢任何帮助。
我找到了答案。我必须使用 BitBlt,这样出现在控制面上的所有东西都会被保存。
private void button4_Click(object sender, EventArgs e)
{
var bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
using (var bmpGraphics = Graphics.FromImage(bmp))
{
var despDC = bmpGraphics.GetHdc();
using (Graphics formGraphics = Graphics.FromHwnd(pictureBox1.Handle))
{
var srcDC = formGraphics.GetHdc();
BitBlt(despDC, 0, 0, pictureBox1.Width, pictureBox1.Height, srcDC, 0, 0, SRCCOPY);
formGraphics.ReleaseHdc(srcDC);
}
bmpGraphics.ReleaseHdc(despDC);
}
bmp.Save("map1.jpg");