Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将桌面窗口保存为一半大小?_C#_.net_Winforms - Fatal编程技术网

C# 如何将桌面窗口保存为一半大小?

C# 如何将桌面窗口保存为一半大小?,c#,.net,winforms,C#,.net,Winforms,这是我现在使用的form1中的代码。 我每秒都用定时器捕捉桌面窗口。 最后我有一个按钮点击事件,如果我点击它,它将从所有保存的gif文件在我的硬盘上创建动画gif文件 但是,当我在internet explorer上加载/运行动画gif时,我在整个屏幕上看到的动画更大,因此每次我都需要使用并移动滚动条才能看到它 例如,如何保存桌面窗口的一半大小? 现在我的硬盘上有大约100个gif文件,每个文件大小为380-407kb using System; using System.Collections

这是我现在使用的form1中的代码。 我每秒都用定时器捕捉桌面窗口。 最后我有一个按钮点击事件,如果我点击它,它将从所有保存的gif文件在我的硬盘上创建动画gif文件

但是,当我在internet explorer上加载/运行动画gif时,我在整个屏幕上看到的动画更大,因此每次我都需要使用并移动滚动条才能看到它

例如,如何保存桌面窗口的一半大小? 现在我的硬盘上有大约100个gif文件,每个文件大小为380-407kb

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using System.IO;
using unfreez_wrapper;

namespace CapturedDesktop
{
    public partial class Form1 : Form
    {
        int screens;
        string gifsdirectory;
        UnFreezWrapper unfreez;

        public Form1()
        {
            InitializeComponent();

            unfreez = new UnFreezWrapper();
            timer1.Enabled = false;
            screens = 0;
            gifsdirectory = @"C:\Temp\CapturedDesktop\";
        }


        private void CaptureScreenshot()
        {
            screens++;
            screenshots(gifsdirectory + screens.ToString("D6") + ".gif");
        }

        public static void screenshots(string filename)
        {
            //Create a new bitmap.
            var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                           Screen.PrimaryScreen.Bounds.Height,
                                           PixelFormat.Format32bppArgb);

            // Create a graphics object from the bitmap.
            var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            // Take the screenshot from the upper left corner to the right bottom corner.
            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                                        Screen.PrimaryScreen.Bounds.Y,
                                        0,
                                        0,
                                        Screen.PrimaryScreen.Bounds.Size,
                                        CopyPixelOperation.SourceCopy);

            // Save the screenshot to the specified path that the user has chosen.
            bmpScreenshot.Save(filename, ImageFormat.Gif);
            bmpScreenshot.Dispose();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            CaptureScreenshot();
        }

        private void AnimatedGifButton_Click(object sender, EventArgs e)
        {
            List<string> myGifList = new List<string>();
            FileInfo[] fi;
            DirectoryInfo dir1 = new DirectoryInfo(gifsdirectory);
            fi = dir1.GetFiles("*.gif");
            for (int i = 0; i < fi.Length; i++)
            {
                myGifList.Add(fi[i].FullName);
            }
            unfreez.MakeGIF(myGifList, gifsdirectory + "agif", 100, true);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用System.Runtime.InteropServices;
使用系统、绘图、成像;
使用System.IO;
使用unfreez_包装器;
命名空间CapturedDesktop
{
公共部分类Form1:Form
{
int屏幕;
字符串gifsdirectory;
解冻包装器解冻;
公共表格1()
{
初始化组件();
unfreez=新的UnFreezWrapper();
timer1.Enabled=false;
屏幕=0;
gifsdirectory=@“C:\Temp\CapturedDesktop\”;
}
私有无效捕获截图()
{
屏幕++;
屏幕截图(gifsdirectory+screens.ToString(“D6”)+“.gif”);
}
公共静态无效屏幕截图(字符串文件名)
{
//创建一个新位图。
var bmpScreenshot=新位图(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);
//从位图创建图形对象。
var gfxScreenshot=Graphics.FromImage(bmpScreenshot);
//从左上角到右下角截图。
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
//将屏幕截图保存到用户选择的指定路径。
保存(文件名,ImageFormat.Gif);
bmpScreenshot.Dispose();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
}
私有无效计时器1_刻度(对象发送方,事件参数e)
{
捕获截图();
}
私有void AnimatedGifButton_单击(对象发送者,事件参数e)
{
List myGifList=新列表();
FileInfo[]fi;
DirectoryInfo dir1=新的DirectoryInfo(gifsdirectory);
fi=dir1.GetFiles(“*.gif”);
对于(int i=0;i

我想截取整个桌面窗口的屏幕截图,但在显示时,显示的窗口不会太大。

您可以从这里更改大小

public static void screenshots(string filename)
{
//Create a new bitmap.
var bmpScreenshot = new Bitmap(
                                (Screen.PrimaryScreen.Bounds.Width - 100),
                                (Screen.PrimaryScreen.Bounds.Height - 100),
                                PixelFormat.Format32bppArgb
                              );
// other code
}

这将创建一个比屏幕短100px的
位图
对象。

您可以从这里更改大小

public static void screenshots(string filename)
{
//Create a new bitmap.
var bmpScreenshot = new Bitmap(
                                (Screen.PrimaryScreen.Bounds.Width - 100),
                                (Screen.PrimaryScreen.Bounds.Height - 100),
                                PixelFormat.Format32bppArgb
                              );
// other code
}

这将创建一个比屏幕短100px的
位图
对象。

您可以从这里更改大小

public static void screenshots(string filename)
{
//Create a new bitmap.
var bmpScreenshot = new Bitmap(
                                (Screen.PrimaryScreen.Bounds.Width - 100),
                                (Screen.PrimaryScreen.Bounds.Height - 100),
                                PixelFormat.Format32bppArgb
                              );
// other code
}

这将创建一个比屏幕短100px的
位图
对象。

您可以从这里更改大小

public static void screenshots(string filename)
{
//Create a new bitmap.
var bmpScreenshot = new Bitmap(
                                (Screen.PrimaryScreen.Bounds.Width - 100),
                                (Screen.PrimaryScreen.Bounds.Height - 100),
                                PixelFormat.Format32bppArgb
                              );
// other code
}

这将创建一个比屏幕短100像素的
位图
对象。

您可以像这样更改
屏幕截图
功能:

public static void screenshots(string filename)
{
    //Create a new bitmap.
    var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                   Screen.PrimaryScreen.Bounds.Height,
                                   PixelFormat.Format32bppArgb);

    // Create a graphics object from the bitmap.
    var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

    // Take the screenshot from the upper left corner to the right bottom corner.
    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                                Screen.PrimaryScreen.Bounds.Y,
                                0,
                                0,
                                Screen.PrimaryScreen.Bounds.Size,
                                CopyPixelOperation.SourceCopy);

    // Save the screenshot to the specified path that the user has chosen.
    //bmpScreenshot.Save(filename, ImageFormat.Gif);
    //bmpScreenshot.Dispose();

    var bmpHalfSize = new Bitmap(Screen.PrimaryScreen.Bounds.Width / 2,
        Screen.PrimaryScreen.Bounds.Height / 2,
        System.Drawing.Imaging.PixelFormat.Format32bppArgb);

    var g = Graphics.FromImage(bmpHalfSize);

    g.DrawImage(bmpScreenshot, 0, 0, CInt(Screen.PrimaryScreen.Bounds.Width / 2), CInt(Screen.PrimaryScreen.Bounds.Height / 2));

    bmpHalfSize.Save(filename, ImageFormat.Gif);
    bmpHalfSize.Dispose();

    bmpScreenshot.Dispose();

}
请注意:在玩
图形时,最好采用
,以便提供方便的语法,确保正确使用
IDisposable
对象

例如:

using (Graphics g = Graphics.FromImage(bmpHalfSize)) {
    g.DrawImage(bmpScreenshot, 0, 0, CInt(Screen.PrimaryScreen.Bounds.Width / 2), CInt(Screen.PrimaryScreen.Bounds.Height / 2));
}

您可以像这样更改
屏幕截图
功能:

public static void screenshots(string filename)
{
    //Create a new bitmap.
    var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                   Screen.PrimaryScreen.Bounds.Height,
                                   PixelFormat.Format32bppArgb);

    // Create a graphics object from the bitmap.
    var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

    // Take the screenshot from the upper left corner to the right bottom corner.
    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                                Screen.PrimaryScreen.Bounds.Y,
                                0,
                                0,
                                Screen.PrimaryScreen.Bounds.Size,
                                CopyPixelOperation.SourceCopy);

    // Save the screenshot to the specified path that the user has chosen.
    //bmpScreenshot.Save(filename, ImageFormat.Gif);
    //bmpScreenshot.Dispose();

    var bmpHalfSize = new Bitmap(Screen.PrimaryScreen.Bounds.Width / 2,
        Screen.PrimaryScreen.Bounds.Height / 2,
        System.Drawing.Imaging.PixelFormat.Format32bppArgb);

    var g = Graphics.FromImage(bmpHalfSize);

    g.DrawImage(bmpScreenshot, 0, 0, CInt(Screen.PrimaryScreen.Bounds.Width / 2), CInt(Screen.PrimaryScreen.Bounds.Height / 2));

    bmpHalfSize.Save(filename, ImageFormat.Gif);
    bmpHalfSize.Dispose();

    bmpScreenshot.Dispose();

}
请注意:在玩
图形时,最好采用
,以便提供方便的语法,确保正确使用
IDisposable
对象

例如:

using (Graphics g = Graphics.FromImage(bmpHalfSize)) {
    g.DrawImage(bmpScreenshot, 0, 0, CInt(Screen.PrimaryScreen.Bounds.Width / 2), CInt(Screen.PrimaryScreen.Bounds.Height / 2));
}

您可以像这样更改
屏幕截图
功能:

public static void screenshots(string filename)
{
    //Create a new bitmap.
    var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                   Screen.PrimaryScreen.Bounds.Height,
                                   PixelFormat.Format32bppArgb);

    // Create a graphics object from the bitmap.
    var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

    // Take the screenshot from the upper left corner to the right bottom corner.
    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                                Screen.PrimaryScreen.Bounds.Y,
                                0,
                                0,
                                Screen.PrimaryScreen.Bounds.Size,
                                CopyPixelOperation.SourceCopy);

    // Save the screenshot to the specified path that the user has chosen.
    //bmpScreenshot.Save(filename, ImageFormat.Gif);
    //bmpScreenshot.Dispose();

    var bmpHalfSize = new Bitmap(Screen.PrimaryScreen.Bounds.Width / 2,
        Screen.PrimaryScreen.Bounds.Height / 2,
        System.Drawing.Imaging.PixelFormat.Format32bppArgb);

    var g = Graphics.FromImage(bmpHalfSize);

    g.DrawImage(bmpScreenshot, 0, 0, CInt(Screen.PrimaryScreen.Bounds.Width / 2), CInt(Screen.PrimaryScreen.Bounds.Height / 2));

    bmpHalfSize.Save(filename, ImageFormat.Gif);
    bmpHalfSize.Dispose();

    bmpScreenshot.Dispose();

}
请注意:在玩
图形时,最好采用
,以便提供方便的语法,确保正确使用
IDisposable
对象

例如:

using (Graphics g = Graphics.FromImage(bmpHalfSize)) {
    g.DrawImage(bmpScreenshot, 0, 0, CInt(Screen.PrimaryScreen.Bounds.Width / 2), CInt(Screen.PrimaryScreen.Bounds.Height / 2));
}

您可以像这样更改
屏幕截图
功能:

public static void screenshots(string filename)
{
    //Create a new bitmap.
    var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                   Screen.PrimaryScreen.Bounds.Height,
                                   PixelFormat.Format32bppArgb);

    // Create a graphics object from the bitmap.
    var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

    // Take the screenshot from the upper left corner to the right bottom corner.
    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                                Screen.PrimaryScreen.Bounds.Y,
                                0,
                                0,
                                Screen.PrimaryScreen.Bounds.Size,
                                CopyPixelOperation.SourceCopy);

    // Save the screenshot to the specified path that the user has chosen.
    //bmpScreenshot.Save(filename, ImageFormat.Gif);
    //bmpScreenshot.Dispose();

    var bmpHalfSize = new Bitmap(Screen.PrimaryScreen.Bounds.Width / 2,
        Screen.PrimaryScreen.Bounds.Height / 2,
        System.Drawing.Imaging.PixelFormat.Format32bppArgb);

    var g = Graphics.FromImage(bmpHalfSize);

    g.DrawImage(bmpScreenshot, 0, 0, CInt(Screen.PrimaryScreen.Bounds.Width / 2), CInt(Screen.PrimaryScreen.Bounds.Height / 2));

    bmpHalfSize.Save(filename, ImageFormat.Gif);
    bmpHalfSize.Dispose();

    bmpScreenshot.Dispose();

}
请注意:在玩
图形时,最好采用
,以便提供方便的语法,确保正确使用
IDisposable
对象

例如:

using (Graphics g = Graphics.FromImage(bmpHalfSize)) {
    g.DrawImage(bmpScreenshot, 0, 0, CInt(Screen.PrimaryScreen.Bounds.Width / 2), CInt(Screen.PrimaryScreen.Bounds.Height / 2));
}

使用此功能可以裁剪图像,而不是调整其大小。我说的对吗?使用此功能,您可以裁剪图像,而不是调整其大小。我说的对吗?使用此功能,您可以裁剪图像,而不是调整其大小。我说的对吗?使用此功能,您可以裁剪图像,而不是调整其大小。我说得对吗?