使用C#拍摄设备屏幕的屏幕截图 [英] Taking screenshot of a device screen using c#
本文介绍了使用C#拍摄设备屏幕的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hii ...
有什么方法可以获取在WIN CE5.0设备屏幕上运行的应用程序的屏幕快照。
Thanxxx。...
Hii... Is there any way to take screenshot of the application running on WIN CE5.0 device screen. Thanxxx in advance....
推荐答案
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
namespace ScreenShot
{
public class Program
{
enum RasterOperation : uint { SRC_COPY = 0x00CC0020 }
[DllImport("coredll.dll")]
static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, RasterOperation rasterOperation);
[DllImport("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("coredll.dll")]
private static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
static void Main(String[] args)
{
Rectangle bounds = Screen.PrimaryScreen.Bounds;
IntPtr hdc = GetDC(IntPtr.Zero);
Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format16bppRgb565);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
IntPtr dstHdc = graphics.GetHdc();
BitBlt(dstHdc, 0, 0, bounds.Width, bounds.Height, hdc, 0, 0,
RasterOperation.SRC_COPY);
graphics.ReleaseHdc(dstHdc);
}
bitmap.Save("screenshot.jpg", ImageFormat.Jpeg);
ReleaseDC(IntPtr.Zero, hdc);
}
}
}
这篇关于使用C#拍摄设备屏幕的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文