怎么用c#窗体做截屏功能 求代码
1个回答
展开全部
/// <summary>
/// 截取窗体内任意位置成图片,自动保存到项目Play文件夹中img.jpg文件.
/// </summary>
/// <param name="location_X">开始位置X坐标</param>
/// <param name="location_Y">开始位置Y坐标</param>
/// <param name="size_X">图片大小宽度</param>
/// <param name="size_Y">图片大小高度</param>
private void SubPictureAutoSave(int location_X, int location_Y, int size_X, int size_Y)
{
Bitmap bitSize = new Bitmap(size_X, size_Y);
Graphics g = Graphics.FromImage(bitSize);
Point pl = new Point(this.Location.X + location_X, this.Location.Y + location_Y);
g.CopyFromScreen(pl, new Point(0, 0), bitSize.Size);
bitSize.Save(Application.StartupPath + "\\PlayImg\\img.jpg");
g.Dispose();
}
/// <summary>
/// 截取窗体内任意位置,另存为图片.
/// </summary>
/// <param name="location_X">开始位置X坐标</param>
/// <param name="location_Y">开始位置Y坐标</param>
/// <param name="size_X">图片大小宽度</param>
/// <param name="size_Y">图片大小高度</param>
private void SubPictureSaveAs(int location_X, int location_Y, int size_X, int size_Y)
{
Bitmap bitSize = new Bitmap(size_X, size_Y);
Graphics g = Graphics.FromImage(bitSize);
Point pl = new Point(this.Location.X + location_X, this.Location.Y + location_Y);
g.CopyFromScreen(pl, new Point(0, 0), bitSize.Size);
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "jpg|*.jpg|bmp|*.bmp|gif|*.gif";
saveFileDialog.FileName = "img" + DateTime.Now.ToString("yyyyMMddHHmmss");
if (saveFileDialog.ShowDialog() != DialogResult.Cancel)
{
bitSize.Save(saveFileDialog.FileName);
}
g.Dispose();
}
更多追问追答
追问
我要做的是能截取窗体之外任意部分的功能 就类似搜狗输入法截屏的那种
我要做的是能截取窗体之外任意部分的功能 就类似搜狗输入法截屏的那种
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询