Michael Knight
Lurker
I am using the following code to return a bitmap from a video using jni then to display it using c++ and Openframeworks.You may not be familiar with Openframeworks but it's just the last step, possibly there is an error with the code before using Openframeworks' ofImage object.
These codes are able to grab a frame from a video and then display it but unfortunately instead of one full image it displays four small images next to each other.How can I solve this problem?
Here is the code:
These codes are able to grab a frame from a video and then display it but unfortunately instead of one full image it displays four small images next to each other.How can I solve this problem?
Here is the code:
Code:
setup() function:
{
jclass bitmapConfig = (*env)-> FindClass(env,"android/graphics/Bitmap$Config");
jfieldID rgba8888FieldID = (*env)->GetStaticFieldID(env,bitmapConfig, "ARGB_8888", "Landroid/graphics/Bitmap$Config;");
jobject rgba8888Obj = (*env)->GetStaticObjectField(env,bitmapConfig, rgba8888FieldID);
jclass mediadataret = (*env) -> FindClass(env,"android/media/MediaMetadataRetriever");
jmethodID medID = (*env)->GetMethodID(env,mediadataret,"<init>","()V");
jstring str1 = (*env)->NewStringUTF (env, "/storage/emulated/0/deneme1/MOV_0270.mp4" ) ;
(*env)->CallVoidMethod(env,mediadatart,medID2,str1);
jclass classbitmap = (*env)->FindClass(env,"android/graphics/Bitmap");
jmethodID createBitmapMethodID = (*env)()-> GetStaticMethodID(env,classbitmap,"createBitmap",
(IILandroid/graphics/Bitmap$Config;)
Landroid/graphics/Bitmap;");
jobject bitmap1= (*env)->CallStaticObjectMethod(env,classbitmap, createBitmapMethodID, _width,_height, rgba8888Obj);
jmethodID medID3 = (*env)->GetMethodID(env,mediadataret,"getFrameAtTime","(J)Landroid/graphics/Bitmap;");
bitmap1 = (*env)->CallObjectMethod(env,mediadatart,medID3,framenum);
jmethodID metID4 = (*env)->GetMethodID(env,classbitmap,"getPixels","([IIIIIII)V");
jmethodID widthget = (*env)->GetMethodID(env,classbitmap,"getWidth","()I");
jmethodID heightget = (*env)->GetMethodID(env,classbitmap,"getHeight","()I");
jlong framenum=7*1000;
jint offset=0;
jint stride=1;
jint x=0;
jint y=0;
jint width= (*env)->CallIntMethod(env,bitmap1,widthget);
jint height = (*env)->CallIntMethod(env,bitmap1,heightget);
jintArray pixels = (*env)->NewIntArray(env,width * height*4);
(*env)-> CallVoidMethod(env, bitmap1,metID4,pixels,offset,width,x,y,width,height);
int* pixelsp = new int[width*height*4];
(*env)->GetIntArrayRegion(env,pixels,0,width*height,pixelsp);
bitmap = new unsigned char[width*height*4];
for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) {
int index = 4 * ( x + width * y );
unsigned char red = pixelsp[index]>>16 ;
unsigned char green = pixelsp[index+1 ]>>8;
unsigned char blue = pixelsp[index+2];
unsigned char alpha = pixelsp[index+3] >> 24;
bitmap[index]=red;
bitmap[index+1]=green;
bitmap[index+2]=blue;
bitmap[index+3]=alpha;
}
}
image1.setFromPixels(bitmap, width, height, ofImageType::OF_IMAGE_COLOR_ALPHA,true);
ofBackground(255,255,255);
width__=width;
height__=height;
}
draw() function:
{
ofSetColor( 255, 255, 255 );
image1.draw(50,50,width__,height__);