ScreenToGif/Util/Other.cs
(开头部分) 14KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using ScreenToGif.FileWriters;
using ScreenToGif.Util.Model;
using SaveFileDialog = Microsoft.Win32.SaveFileDialog;
namespace ScreenToGif.Util
{
/// <summary>
/// Other helper methods.
/// </summary>
public static class Other
{
public static Point TransformToScreen(Point point, Visual relativeTo)
{
var hwndSource = PresentationSource.FromVisual(relativeTo) as HwndSource;
var root = hwndSource.RootVisual;
// Translate the point from the visual to the root.
var transformToRoot = relativeTo.TransformToAncestor(root);
var pointRoot = transformToRoot.Transform(point);
// Transform the point from the root to client coordinates.
var m = Matrix.Identity;
var transform = VisualTreeHelper.GetTransform(root);
if (transform != null)
{
m = Matrix.Multiply(m, transform.Value);
}
var offset = VisualTreeHelper.GetOffset(root);
m.Translate(offset.X, offset.Y);
var pointClient = m.Transform(pointRoot);
// Convert from “device-independent pixels” into pixels.
pointClient = hwndSource.CompositionTarget.TransformToDevice.Transform(pointClient);
var pointClientPixels = new Native.PointW();
pointClientPixels.X = (0 < pointClient.X) ? (int)(pointClient.X + 0.5) : (int)(pointClient.X - 0.5);
pointClientPixels.Y = (0 < pointClient.Y) ? (int)(pointClient.Y + 0.5) : (int)(pointClient.Y - 0.5);
// Transform the point into screen coordinates.
var pointScreenPixels = pointClientPixels;
Native.ClientToScreen(hwndSource.Handle, ref pointScreenPixels);
//Native.GetCurrentPositionEx(hwndSource.Handle, out pointScreenPixels);
//Native.GetWindowOrgEx(hwndSource.Handle, out pointScreenPixels);
return new Point(pointScreenPixels.X, pointScreenPixels.Y);
}
后面还有 337 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
