如何在Windows中将屏幕截图直接保存到文件中?
在Windows中有没有一种一键式的方法可以将屏幕截图直接保存到文件中如何在Windows中将屏幕截图直接保存到文件中?,windows,screenshot,Windows,Screenshot,在Windows中有没有一种一键式的方法可以将屏幕截图直接保存到文件中 对于Windows 8和10,SoftwareEdi准确地回答了上述问题。下面是为后代保留的原始额外材料。 这是一个非常重要的问题,正如2021年的316K视图所示。 在2008年被问到,所以在2015年左右结束了这个问题,因为这个问题离题了, 可能是因为下面最后一个问题 在Windows XP中,可以按Alt PrintScreen复制 活动窗口,或Ctrl-PrintScreen以复制完整图像 桌面 然后可以将其粘贴到
对于Windows 8和10,SoftwareEdi准确地回答了上述问题。下面是为后代保留的原始额外材料。 这是一个非常重要的问题,正如2021年的316K视图所示。 在2008年被问到,所以在2015年左右结束了这个问题,因为这个问题离题了, 可能是因为下面最后一个问题 在Windows XP中,可以按Alt PrintScreen复制 活动窗口,或Ctrl-PrintScreen以复制完整图像 桌面 然后可以将其粘贴到接受图像的应用程序中: Photoshop、微软Word等 我想知道:有没有办法把截图直接保存到 文件我真的需要打开一个图像程序吗 net或Photoshop,只需粘贴图像,然后保存
据我所知,在XP中,是的,您必须使用其他应用程序来实际保存它
Vista附带了剪切工具,简化了一点过程 在不安装屏幕截图自动保存实用程序的情况下,您可以这样做。有几个实用程序,你可以找到,但在做这件事
例如:您可以编写一些非常简单的代码,用于挂接PrintScreen并将捕获保存到文件中 下面是一些开始捕获并保存到文件的内容。您只需勾选“打印屏幕”键即可
使用系统;
使用系统图;
使用System.IO;
使用系统、绘图、成像;
使用System.Runtime.InteropServices;
公共类捕获屏幕
{
静态公共void Main(字符串[]args)
{
尝试
{
位图捕获=CaptureScreen.GetDesktopImage();
字符串文件=Path.Combine(Environment.CurrentDirectory,“screen.gif”);
ImageFormat=ImageFormat.Gif;
保存(文件、格式);
}
捕获(例外e)
{
控制台写入线(e);
}
}
公共静态位图GetDesktopImage()
{
WIN32_API.SIZE;
IntPtr hDC=WIN32_API.GetDC(WIN32_API.GetDesktopWindow());
IntPtr hMemDC=WIN32_API.CreateCompatibleDC(hDC);
size.cx=WIN32_API.GetSystemMetrics(WIN32_API.SM_CXSCREEN);
size.cy=WIN32_API.GetSystemMetrics(WIN32_API.SM_CYSCREEN);
m_HBitmap=WIN32_API.CreateCompatibleBitmap(hDC,size.cx,size.cy);
如果(m_HBitmap!=IntPtr.Zero)
{
IntPtr hOld=(IntPtr)WIN32_API.SelectObject(hMemDC,m_HBitmap);
WIN32_API.BitBlt(hMemDC,0,0,size.cx,size.cy,hDC,0,0,WIN32_API.SRCCOPY);
WIN32_API。选择对象(hMemDC,保持);
WIN32_API.DeleteDC(hMemDC);
WIN32_API.ReleaseDC(WIN32_API.GetDesktopWindow(),hDC);
返回系统。图纸。图像。来自HBitmap(m_HBitmap);
}
返回null;
}
受保护的静态IntPtr m_HBitmap;
}
公共类WIN32_API
{
公共结构大小
{
公共int cx;
公共关系;
}
public const int SRCCOPY=13369376;
公共const int SM_CXSCREEN=0;
公共const int SM_CYSCREEN=1;
[DllImport(“gdi32.dll”,EntryPoint=“deleteddc”)]
公共静态外部IntPtr DeleteDC(IntPtr hDc);
[DllImport(“gdi32.dll”,EntryPoint=“DeleteObject”)]
公共静态外部IntPtr DeleteObject(IntPtr hDc);
[DllImport(“gdi32.dll”,EntryPoint=“BitBlt”)]
公共静态外部bool BitBlt(IntPtr hdcDest、intxdest、intydest、intwdest、inthdest、IntPtr hdcSource、intxsrc、intysrc、intrasterop);
[DllImport(“gdi32.dll”,EntryPoint=“CreateCompatibleBitmap”)]
公共静态外部IntPtr CreateCompatibleBitmap(IntPtr hdc、int nWidth、int nHeight);
[DllImport(“gdi32.dll”,EntryPoint=“CreateCompatibleDC”)]
公共静态外部IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport(“gdi32.dll”,EntryPoint=“SelectObject”)]
公共静态外部IntPtr SelectObject(IntPtr hdc、IntPtr bmp);
[DllImport(“user32.dll”,EntryPoint=“GetDesktopWindow”)]
公共静态外部IntPtr GetDesktopWindow();
[DllImport(“user32.dll”,EntryPoint=“GetDC”)]
公共静态外部IntPtr GetDC(IntPtr ptr);
[DllImport(“user32.dll”,EntryPoint=“GetSystemMetrics”)]
公共静态外部intgetsystemmetrics(intabc);
[DllImport(“user32.dll”,EntryPoint=“GetWindowDC”)]
公共静态外部IntPtr GetWindowDC(Int32 ptr);
[DllImport(“user32.dll”,EntryPoint=“ReleaseDC”)]
公共静态外部IntPtr ReleaseDC(IntPtr hWnd、IntPtr hDc);
}
更新
下面是从C#钩住打印屏幕(和其他键)的代码:
当然,您可以编写一个程序来监视剪贴板,并为剪贴板中的每个图像显示一个恼人的“另存为”对话框;-)。我想你甚至可以知道最后按下的键是否是PrintScreen,以限制误报的数量 当我在想的时候。。你也可以在谷歌上搜索已经做到这一点的人
编辑:。。或者只是等待有人在这里发布源代码(碰巧:-)您需要一个第三方屏幕抓取实用程序来实现XP中的该功能。我觉得Scott Hanselman很广泛,通常会在那里寻找这样一个实用程序——当然,他在博客上写过一对夫妇。Snagit……很多技术人员都使用它。你可能想要这样的东西:
我认为有一个IE版本,也有一个与Explorer集成的版本。非常好的软件。在Windows 8之前,如果没有第三方工具,就无法直接保存到文件。以下是我个人最喜欢的非第三方工具解决方案 适用于Windows 8及更高版本 +PrintScreen将屏幕截图保存到
/Pictures/Screenshots
适用于Windows 7
在Win7中,只需使用剪切工具:按开始键,然后键入“sni”(回车)即可轻松访问。或
然后sni进入
Windows的早期版本
我使用下面的键盘com
function TForm1.GetScreenShot(OnlyActiveWindow: boolean) : TBitmap;
var
w,h : integer;
DC : HDC;
hWin : Cardinal;
r : TRect;
begin
//take a screenshot and return it as a TBitmap.
//if they specify "OnlyActiveWindow", then restrict the screenshot to the
//currently focused window (same as alt-prtscrn)
//Otherwise, get a normal screenshot (same as prtscrn)
Result := TBitmap.Create;
if OnlyActiveWindow then begin
hWin := GetForegroundWindow;
dc := GetWindowDC(hWin);
GetWindowRect(hWin,r);
w := r.Right - r.Left;
h := r.Bottom - r.Top;
end //if active window only
else begin
hWin := GetDesktopWindow;
dc := GetDC(hWin);
w := GetDeviceCaps(DC,HORZRES);
h := GetDeviceCaps(DC,VERTRES);
end; //else entire desktop
try
Result.Width := w;
Result.Height := h;
BitBlt(Result.Canvas.Handle,0,0,Result.Width,Result.Height,DC,0,0,SRCCOPY);
finally
ReleaseDC(hWin, DC) ;
end; //try-finally
end;
procedure TForm1.btnSaveScreenshotClick(Sender: TObject);
var
bmp : TBitmap;
savdlg : TSaveDialog;
begin
//take a screenshot, prompt for where to save it
savdlg := TSaveDialog.Create(Self);
bmp := GetScreenshot(False);
try
if savdlg.Execute then begin
bmp.SaveToFile(savdlg.FileName);
end;
finally
FreeAndNil(bmp);
FreeAndNil(savdlg);
end; //try-finally
end;