Created
November 9, 2014 05:31
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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