If you have never used JNI before, I recommend that you take a look at the JNI Programmers Guide and Specification .
In general, you need to do the following:
- Create a Java method with the
native keyword without implementation. - use the
javah command in a class with its own method to create a header file (.h). javah comes with a JDK installation. - implement native Java function in C / C ++.
- find the java.awt.image.BufferedImage class.
- Find the constructor you want to use.
- create a BufferedImage object with the specified constructor.
- find the setPixel method.
- run this method to set each pixel value in your image. you will need to run its height x width times.
- return an object.
- compile your own file into a shared library.
- load your shared library into your java class.
- run your java class with a link to your shared library.
There are other ways to copy the raw data of your image, but as I explained, should be enough.
source share