c#远程桌面连接解决方案

c#远程桌面连接解决方案,c#,image,graph,image-resizing,C#,Image,Graph,Image Resizing,我正在编写一个类似于TeamViewer的程序。但我有一个问题,屏幕分辨率太高。如何降低传入图片的质量 byte[] ScreenShut() { Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height); Graphics gr = Graphics.FromImage(bmp); bmp.SetResolution(96.0F,96.0F

我正在编写一个类似于TeamViewer的程序。但我有一个问题,屏幕分辨率太高。如何降低传入图片的质量

byte[] ScreenShut()
{
    Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);

    Graphics gr = Graphics.FromImage(bmp);
    bmp.SetResolution(96.0F,96.0F);
    gr.CopyFromScreen(0, 0, 0, 0, new Size(bmp.Width, bmp.Height));
    MemoryStream ms = new MemoryStream();
    bmp.Save(ms, ImageFormat.Png);
    return ms.GetBuffer();
}

从graphics.CopyFromScreen()创建位图,然后创建另一个位图以进行缩放,从而浪费太多cpu

[DllImport("user32")] static extern int GetDC(int hWnd);
[DllImport("user32")] static extern int ReleaseDC(int hwnd, int hDC)
[DllImport("gdi32")] static extern int StretchBlt(int hdc, int x, int y, int nWidth, int nHeight, int hSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, int dwRop);

        int W = Screen.PrimaryScreen.Bounds.Width;
        int H = Screen.PrimaryScreen.Bounds.Height;
        int dW = W * 2 / 3; // 66%
        int dH = H * 2 / 3; // 66%

        Bitmap img = new Bitmap(dW, dH);
        Graphics g = Graphics.FromImage(img);
        var dc = g.GetHdc();
        var screen = GetDC(0);
        StretchBlt(dc.ToInt32(), 0, 0, dW, dH, screen, 0, 0, W, H, 0xCC0020);
        g.ReleaseHdc(dc) ;
        ReleaseDC(0, screen)

        img.Save(@"C:\123.png", ImageFormat.Jpeg);

缩放图像后,文本将变得难以阅读。缩放比例应在75%左右,然后使用JPG压缩格式缩小大小。

您是否尝试过
新位图(Screen.PrimaryScreen.Bounds.Width/2、Screen.PrimaryScreen.Bounds.Height/2)
?只需创建屏幕分辨率一半大小的位图。一旦这起作用,您可以决定缩小尺寸的百分比。这称为自动缩放。当我这样做时,它占据屏幕的某一部分;然后继续使用原始代码,然后调整位图的大小。请参阅: