Graphics.CopyFromScreen截取Windows照片查看器中图片出现白点的问题

微wx笑
Java领域优质创作者
博客专家认证
2014-11-17 03:38:23
Graphics.CopyFromScreen使用CopyPixelOperation.SourceCopy参数
但是截取Windows照片查看器中图片会出现白色杂点,不知道是什么原因,
有人遇到过吗?望高手指点一二,小弟在此谢过了!

问题截图:

使用的代码参考:C#软件开发实例.私人订制自己的屏幕截图工具(二)创建项目、注册热键、显示截图主窗口 文章中的截图窗口实现原理部分

尝试使用NativeMethod,也是存在同样的问题,代码如下:
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll", EntryPoint = "BitBlt")]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool BitBlt([System.Runtime.InteropServices.InAttribute()] System.IntPtr hdc, int x, int y, int cx, int cy, [System.Runtime.InteropServices.InAttribute()] System.IntPtr hdcSrc, int x1, int y1, uint rop);


...全文
465 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
小哥哥 2014-11-23
  • 打赏
  • 举报
回复
估计是压缩算法的问题,生成png的图片可能不会
微wx笑 2014-11-22
  • 打赏
  • 举报
回复
现在都没人玩c#了?
微wx笑 2014-11-17
  • 打赏
  • 举报
回复
测试结果:
唉,没救了,上传图片一直提示上传超时。
微wx笑 2014-11-17
  • 打赏
  • 举报
回复
引用 2 楼 Z65443344 的回复:


public Bitmap GetScreenBmp(Rectangle rect)
{
Bitmap screenBmp = new Bitmap(rect.Width, rect.Height);

using (Graphics g = Graphics.FromImage(screenBmp))
{
g.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size);
Cursor.Current.Draw(g, new Rectangle(Cursor.Position.X, Cursor.Position.Y, 33, 33));
}
return screenBmp;
}

不就是这样用吗,
为什么要使用CopyPixelOperation.SourceCopy参数,怎么用的


非常感谢你的回答,但您应该没有测试这段代码,
除Windows照片查看器之外的窗口都没有问题,至少目前没有发现,唯独截取Windows照片查看器显示的图片时
出现这种情况。
测试代码:
private void button3_Click(object sender, EventArgs e)
{
this.BackgroundImage = GetScreenBmp(new Rectangle(0, 0, Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height));
}
於黾 2014-11-17
  • 打赏
  • 举报
回复


        public Bitmap GetScreenBmp(Rectangle rect)
        {
            Bitmap screenBmp = new Bitmap(rect.Width, rect.Height);

            using (Graphics g = Graphics.FromImage(screenBmp))
            {
                g.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size);
                Cursor.Current.Draw(g, new Rectangle(Cursor.Position.X, Cursor.Position.Y, 33, 33));
            }
            return screenBmp;
        }
不就是这样用吗, 为什么要使用CopyPixelOperation.SourceCopy参数,怎么用的
微wx笑 2014-11-17
  • 打赏
  • 举报
回复
原图:

110,539

社区成员

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

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

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