Skip to content

Instantly share code, notes, and snippets.

@sheimi
Created November 9, 2014 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheimi/cad0f89ed8d0da3ca834 to your computer and use it in GitHub Desktop.
Save sheimi/cad0f89ed8d0da3ca834 to your computer and use it in GitHub Desktop.
code in blog.sheimi.me: 2012-09-05-a-summary-of-using-jni (1)
// CVJNI.java
import java.io.*;
public class CVJNI {
//Load jni library
static {
try {
System.loadLibrary("cvjni");
} catch (Exception e) {
e.printStackTrace();
}
}
//native method
public static native byte[] toBMP(byte[] imageSource);
//main
public static void main(String [] args) {
String input = args[0];
String output = args[1];
FileInputStream fi = null;
FileOutputStream fo = null;
try {
File infile = new File(args[0]);
int len = (int)infile.length();
//get source
fi = new FileInputStream(infile);
byte[] imageSource = new byte[len];
fi.read(imageSource, 0, len);
//revoke native method
byte[] outImage = CVJNI.toBMP(imageSource);
//write
fo = new FileOutputStream(output);
fo.write(outImage);
} catch(IOException e) {
e.printStackTrace();
} finally {
try {
if (fi != null)
fi.close();
if (fo != null)
fo.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment