Document.TouchScreen/Components/ImageHelper.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Interop;
namespace Document.TouchScreen
{
class ImageHelper
{
/// <summary>
/// 保存截图
/// </summary>
/// <param name="ui">控件名称</param>
/// <param name="filename">图片文件名</param>
public static void SaveFrameworkElementToImage(IntPtr handle, int width, int height,string path)
{
try
{
IntPtr hscrdc = GetWindowDC(handle);
//System.Windows.Forms.Control control = System.Windows.Forms.Control.FromHandle(hWnd);
IntPtr hbitmap = CreateCompatibleBitmap(hscrdc, width, height);
IntPtr hmemdc = CreateCompatibleDC(hscrdc);
SelectObject(hmemdc, hbitmap);
PrintWindow(handle, hmemdc, 0);
Bitmap bmp = Bitmap.FromHbitmap(hbitmap);
DeleteDC(hscrdc);//删除用过的对象
DeleteDC(hmemdc);//删除用过的对象
bmp.Save("D:\\5.jpg");
}
catch (Exception ee)
{
}
}
#region import dll
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern IntPtr CreateDC(string driver, string device, IntPtr res1, IntPtr res2);
[DllImport("gdi32.dll")]
public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, int nWidth,
int nHeight, IntPtr hObjSource, int nXSrc, int nYSrc, TernaryRasterOperations dwRop);
public enum TernaryRasterOperations
{
SRCCOPY = 0x00CC0020, /* dest = source*/
SRCPAINT = 0x00EE0086, /* dest = source OR dest*/
后面还有 96 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
