Passing Bitmap to JNI
Hi all How can I pass bitmap image to JNI part for some image manipulation. Is it possible, or do I need to convert to byte array.
Hi all How can I pass bitmap image to JNI part for some image manipulation. Is it possible, or do I need to convert to byte array.
Look at the <NDK dir>/samples/bitmap-plasma
sample.
Hi I just convert my bitmap to byte array and passed to the JNI but getting distorted image at the JNI code. My code look like http://pastebin.com/cwQg6TvZ
I've solved this by ensuring a buffered image is of type BufferedImage.TYPE_3BYTE_BGR)
, converting to a byte array, and then copying into the aligned memory in JNI. Code samples below.
(Conversion to java should be easy)
// converts an image to BufferedImage.TYPE_3BYTE_BGR
def convertType(img: BufferedImage): BufferedImage = {
val convertedImg = new BufferedImage(img.getWidth, img.getHeight, BufferedImage.TYPE_3BYTE_BGR)
convertedImg.getGraphics.drawImage(img, 0, 0, null)
convertedImg
}
IplImage* rgbJbyteToIpl(const int width, const int height, const jbyte* const img) {
int j, channels = 3;
IplImage * rv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
// IplImage data is aligned for SIMD instructions.
// Copy each row individually.
for (j = 0; j < height; j++) {
memcpy((void*) &(rv->imageData[(rv->widthStep) * j]), (void*) &(img[j * width * channels]), width * channels);
}
return 0;
}
in you JNI part, i didn't understand why you're returning 0? Thank you very much
Asked: 2012-11-23 01:43:19 -0600
Seen: 3,390 times
Last updated: Apr 30 '13
Unresolved inclusion in OpenCV+Android tutorial
How the libopencv_java.so is copy to the apk when it is used the static lib type?
Android: Native Opencv - cvtColor segfault
OpenCV4Android sample: "Type 'DetectionBasedTracker' could not be resolved"
FaceRecognizer.java in Opencv4Android 2.4.3
android native template matching [closed]
Why am I getting assertion failed in cvtColor even when convertTo was called in the line before?
How to get good matches from the ORB feature detection algorithm?
How to decrease the number of processed frames from a live video camera?