[英]How do I properly map a `MagImageScalingCallback` using JNA?
I am using jna.jar, jna-3.2.5.jar and jna-3.3.0-platform.jar in my Java Project.我在我的 Java 项目中使用 jna.jar、jna-3.2.5.jar 和 jna-3.3.0-platform.jar。
This is the Winapi function I want to replicate.这是我要复制的 Winapi 函数。
BOOL WINAPI MagImageScalingCallback(
_In_ HWND hwnd,
_In_ void *srcdata,
_In_ MAGIMAGEHEADER srcheader,
_Out_ void *destdata,
_In_ MAGIMAGEHEADER destheader,
_In_ RECT unclipped,
_In_ RECT clipped,
_In_ HRGN dirty
);
This is my Java code这是我的 Java 代码
public interface MagImageScalingCallback extends StdCallLibrary.StdCallCallback{
public boolean MagImageScalingCallback(HWND hwnd,
Pointer srcdata,
MAGIMAGEHEADER.ByValue srcheader,
Pointer destdata,
MAGIMAGEHEADER.ByValue destheader,
RectByValue source,
RectByValue clipped,
HRGN dirty);
}
When I get into this method of the callback, I get unexpected results:当我进入回调的这个方法时,我得到了意想不到的结果:
public boolean MagImageScalingCallback(HWND hwnd, Pointer srcdata,
MAGIMAGEHEADER.ByValue srcheader, Pointer destdata,
MAGIMAGEHEADER.ByValue destheader, RectByValue source, RectByValue clipped, HRGN dirty) {
image.setRGB(0, 0, srcheader.width, srcheader.height, srcdata.getIntArray(0, srcheader.width * srcheader.height ), 0, srcheader.width);
return true;
}
This table explains What works and what doesn't work in 32 bit and 64 bit system when I change the data type of the variables.此表解释了当我更改变量的数据类型时,在 32 位和 64 位系统中哪些有效,哪些无效。
+--------------+--------------+-------------+-------------+
| Parameter | Data type | 64 bit | 32 bit |
+--------------+--------------+-------------+-------------+
| source | WinDef.RECT | Working | Not Working |
| clipped | WinDef.RECT | Working | Not Working |
| source | RectByValue | Working | Working |
| source | RectByValue | Working | Working |
| srcdata | Pointer | Working | Not Working |
| destdata | Pointer | Working | Not Working |
+--------------+--------------+-------------+-------------+
Not working means a totally black image in the result不工作意味着结果中的全黑图像
If I use the above code in a 64 bit system, I can capture the desktop(I can access the data from the Pointer variable).如果我在 64 位系统中使用上面的代码,我可以捕获桌面(我可以从 Pointer 变量访问数据)。 If I use the same code in 32 bit system, I am not getting any image.如果我在 32 位系统中使用相同的代码,我将得不到任何图像。 You can see my whole code你可以看到我的整个代码
Why is the error in my code?为什么我的代码中出现错误? How can I fix that?我该如何解决?
For your Information.供您参考。 As you see in the screenSkip.java
, Whenever MagSetWindowSource function is called.正如您在screenSkip.java
看到的,每当 MagSetWindowSource 函数被调用。 MagImageScalingCallback(in line 80) is called.调用 MagImageScalingCallback(第 80 行)。
Problems in this section of code这一段代码的问题
If I run this code on a 64 bit system srcdata
and destdata
will hold the array of integer pixels of the Desktop(If I save this as image, it captures the desktop).如果我在 64 位系统上运行此代码srcdata
和destdata
将保存桌面的整数像素数组(如果我将其另存为图像,它将捕获桌面)。 But if I run the same code on 32 bit system these both variable array pixel value is always zero(If I save the image, it is always black)但是如果我在 32 位系统上运行相同的代码,这两个变量数组像素值总是零(如果我保存图像,它总是黑色)
@david-heffernan I am running this code on a 32-bit system. @david-heffernan 我在 32 位系统上运行此代码。 I know The Magnification API is not supported under WOW64;
我知道The Magnification API is not supported under WOW64;
. . Which means 32-bit magnification application works on a 32-bit system and 64-bit magnification application works on a 64-bit system.这意味着 32 位放大应用程序适用于 32 位系统,而 64 位放大应用程序适用于 64 位系统。 Please stop commenting that magnification API doesn't work on WOW64 and try to execute this code on a 32-bit system.请停止评论放大 API 在 WOW64 上不起作用并尝试在 32 位系统上执行此代码。
As for your request the below image shows the configuration of my System.至于您的要求,下图显示了我的系统的配置。
The callback is proper - there is no flaw in your code, besides you are using deprecated functions.回调是正确的 - 除了您使用不推荐使用的函数之外,您的代码没有任何缺陷。
Consider using this:考虑使用这个:
try {
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, "JPEG", new File("printed1.jpg"));
} catch (Exception e) {
e.printStackTrace();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.