我正在尝试用c#创建一个屏幕录像机,每当计时器打勾时我都会拍照,但图像尺寸不正确。我已经测试过我正在使用正确的代码来改变表单大小,并且效果很好,但是当我使用它来拍照时,它需要一个区域,只是比它意味着的盒子大一点显示在左上角和仅显示左上角。
bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
gr = Graphics.FromImage(bmp);
gr.CopyFromScreen(0, 0, 0, 0, new Size(bmp.Width, bmp.Height));
bmp.Save("movie"+ picnum+ ".png");
picnum = picnum + 1;
和调整工作大小的代码
Width = Screen.PrimaryScreen.Bounds.Width;
Height = Screen.PrimaryScreen.Bounds.Height;
this.Size = new Size(Width, Height);
编辑:我已经包含了所有代码。
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;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Bitmap bmp;
Graphics gr;
int picnum = 1;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
timer1.Interval = Convert.ToInt32(textBox1.Text);
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
gr = Graphics.FromImage(bmp);
gr.CopyFromScreen(0, 0, 0, 0, new Size(bmp.Width, bmp.Height));
bmp.Save("movie" + picnum + ".png");
picnum = picnum + 1;
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
}
}
}