You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:C# WinForms区域截图时白色/透明背景显示异常

WinForms区域截图异常:白色/透明背景被识别为透明

我正在开发一款基于WinForms的区域选择(支持尺寸调整)并截图的程序,但遇到了白色背景或透明背景被识别为透明的问题。我在Stack Overflow上搜索了CopyFromScreen相关内容,发现有类似现象但症状不符;还尝试了Win32 API的BitBlt,结果依旧。

以下是我的实现代码:

capturePanel.Controls.Clear();
this.TopMost = true;

this.pictureBox = new PictureBox();
this.pictureBox.Size = capturePanel.Size;
this.pictureBox.Location = new Point(0, 0);
this.pictureBox.BackColor = Color.White;
capturePanel.Controls.Add(this.pictureBox);

// 获取capturePanel的屏幕坐标
Point screenPoint = capturePanel.PointToScreen(Point.Empty);

// 屏幕截图逻辑
Bitmap bmp = new Bitmap(capturePanel.Width, capturePanel.Height);

using (Graphics g = Graphics.FromImage(bmp as Image))
{
    g.CopyFromScreen(screenPoint.X, screenPoint.Y, 0, 0, capturePanel.Size);
}

// 将生成的图片设置到PictureBox中
pictureBox.Image = bmp;

问题现象截图:
区域截图白色背景异常

内容的提问来源于stack exchange,提问作者암소메애

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 13:47:21