如何访问 c++ java中的内存映射文件
我有一个 Windows C++ 应用程序,它为经常更新的位图创建内存映射文件。我想访问这个内存映射文件以在java应用程序中显示实时图像。我怎样才能做到这一点?
我知道 FileChannel 可以映射到内存,但我不知道如何访问由另一个进程创建的内存映射文件。
我已经在我的 java 应用程序中使用 JNA,我应该使用它来访问标准 Windows 内存映射文件功能吗?
或者除了内存映射文件之外,您还有其他解决方案来从单独程序创建的图像中显示 java 中的实时图像流吗?
I have a windows c++ application that creates a memory mapped file for a bitmap that is updated frequently. I would like to access to this memory mapped file to display the live image in a java application. How can I do that?
I know that FileChannel can be mapped to memory but I cannot see how to access a memory mapped file created by another process.
I already use JNA in my java application, should I use it to access standard windows memory mapped files functionality?
Or do you have any other solution than the memory mapped file to display a live image stream in java from an image created by a separate program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此处有一个代码示例,它可以使用 JNI 从 C++ 桥接执行您想要的操作(Win32 内存映射文件)到 Java。可能会按原样工作,尽管根据您的情况可能需要对安全性和线程进行一些清理。
There is a code sample here that does what you want using JNI to bridge from C++ (Win32 memory mapped files) to Java. Might just work as is, although some cleanup for security and threading might be needed depending on your scenario.
我终于使用了 jna 和他们提供的platform 库。 Kernel32 包提供访问权限到 CreateFileMapping 和 MapViewOfFile 函数。
I have finaly used jna and the platform library that they provide. The Kernel32 package offers access to the CreateFileMapping and MapViewOfFile functions.
内存映射文件仍然是一个文件。您可以使用 java.io 读取它,或者如果您也希望在 Java 中对其进行内存映射,则可以使用 java.nio 中的 MappedByteBuffer。
A memory mapped file is still a file. You could read it with java.io, or you could use a MappedByteBuffer from java.nio if you want it memory-mapped in Java too.