简体   繁体   English

Windows 放大 API、.NET 和矩阵

[英]Windows Magnification API, .NET and matrices

I'm trying to create a magnifier app in .NET using the Windows Magnification API .我正在尝试使用 Windows Magnification API在 .NET 中创建放大镜应用程序。 I've pretty much got everything working except for actually setting the magnification level (which defaults to 100%).除了实际设置放大级别(默认为 100%)之外,我几乎已经完成了所有工作。 The problem is, I can't find any examples anywhere on the Internet and all the documentation for the API is C++ code.问题是,我在 Internet 上的任何地方都找不到任何示例,并且 API 的所有文档都是 C++ 代码。 This is the particular function I'm having trouble with.这是我遇到问题的特定功能。

bool SetMagFactor(float magfactor)
{
    MAGTRANSFORM matrix;
    memset(&matrix, 0, sizeof(matrix));
    matrix.v[0][0] = magfactor;
    matrix.v[1][1] = magfactor;
    matrix.v[2][2] = 1.0f;
    return MagSetWindowTransform(hwndMag, &matrix);
}

The MAGTRANSFORM structure is defined as follows: MAGTRANSFORM 结构定义如下:

typedef struct tagMAGTRANSFORM {
    float v[3] [3];
} MAGTRANSFORM, *PMAGTRANSFORM;

The most confusing part of this is the memset - I'm not sure what it does or what its equivalent is in .NET, but what's also confusing is the multidimensional array/matrix and how I would handle this in .NET also.其中最令人困惑的部分是memset - 我不确定它在 .NET 中的作用或等效项是什么,但同样令人困惑的是多维数组/矩阵以及我将如何在 .NET 中处理它。

How can I do it?我该怎么做?

The memset is just clearing out the matrix to start with. memset 只是从清除矩阵开始。 You wouldn't need to do this in .NET.您不需要在 .NET 中执行此操作。 I suspect the simplest way of defining the struct in C# would be to specify each element individually:我怀疑在 C# 中定义结构的最简单方法是单独指定每个元素:

public struct MagTransform
{
    readonly float m00;
    readonly float m10;
    readonly float m20;
    readonly float m01;
    readonly float m11;
    readonly float m21;
    readonly float m02;
    readonly float m12;
    readonly float m22;

    public MagTransform(float magnificationFactor) : this()
    {
        m00 = magnificationFactor;
        m11 = magnificationFactor;
        m22 = 1.0f;
    }
}

You may also need to specify the layout - I'm afraid I'm not so hot on marshalling.您可能还需要指定布局 - 恐怕我对编组不太感兴趣。

As you can see, I've assumed the values you want based on the sample code.如您所见,我已经根据示例代码假设了您想要的值。 There will be warnings about unused values, but that's okay.会有关于未使用值的警告,但这没关系。

You could use a fixed buffer instead, and unsafe code... but I think I'd probably use the above.可以改用固定缓冲区和不安全的代码......但我想我可能会使用上面的。 Basically you just need 9 floats.基本上你只需要9个花车。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM