diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/BasicImageDemoActivity.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/BasicImageDemoActivity.java index 766c052d..7850bba9 100644 --- a/cgeDemo/src/main/java/org/wysaid/cgeDemo/BasicImageDemoActivity.java +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/BasicImageDemoActivity.java @@ -215,6 +215,10 @@ public void saveImageBtnClicked(View view) { mImageView.getResultBitmap(new ImageGLSurfaceView.QueryResultBitmapCallback() { @Override public void get(Bitmap bmp) { + if(bmp == null) { + MsgUtil.toastMsg(BasicImageDemoActivity.this, "Get bitmap failed!"); + return; + } final String s = ImageUtil.saveBitmap(bmp); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + s))); mImageView.post(new Runnable() { diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/ImageDeformActivity.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/ImageDeformActivity.java index 1ce17914..256648b0 100644 --- a/cgeDemo/src/main/java/org/wysaid/cgeDemo/ImageDeformActivity.java +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/ImageDeformActivity.java @@ -256,6 +256,10 @@ public void saveImageBtnClicked(View view) { mImageView.getResultBitmap(new ImageGLSurfaceView.QueryResultBitmapCallback() { @Override public void get(final Bitmap bmp) { + if (bmp == null) { + MsgUtil.toastMsg(ImageDeformActivity.this, "Get bitmap failed!"); + return; + } String s = ImageUtil.saveBitmap(bmp); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + s))); } diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/ImageDemoActivity.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/ImageDemoActivity.java index 145e1153..47e9b7ea 100755 --- a/cgeDemo/src/main/java/org/wysaid/cgeDemo/ImageDemoActivity.java +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/ImageDemoActivity.java @@ -73,6 +73,11 @@ public void onClick(View v) { mImageView.getResultBitmap(new ImageGLSurfaceView.QueryResultBitmapCallback() { @Override public void get(final Bitmap bmp) { + if(bmp == null) { + MsgUtil.toastMsg(ImageDemoActivity.this, "Get bitmap failed!"); + return; + } + String s = ImageUtil.saveBitmap(bmp); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + s))); } @@ -213,7 +218,10 @@ public void faceDetectTestCase(View view) { mImageView.getResultBitmap(new ImageGLSurfaceView.QueryResultBitmapCallback() { @Override public void get(final Bitmap bmp) { - + if(bmp == null) { + MsgUtil.toastMsg(ImageDemoActivity.this, "Get bitmap failed!"); + return; + } mImageView.post(new Runnable() { @Override public void run() { diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/TestCaseActivity.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/TestCaseActivity.java index 022b6925..f86ba08b 100644 --- a/cgeDemo/src/main/java/org/wysaid/cgeDemo/TestCaseActivity.java +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/TestCaseActivity.java @@ -167,6 +167,11 @@ public void run() { //To accelerate this, you can add a Bitmap arg for "getResultBitmap", // and reuse the Bitmap instead of recycle it every time. Bitmap dst = handler.getResultBitmap(); + if(dst == null) { + Log.e(LOG_TAG, "getResultBitmap returns null!"); + continue; + } + String s = ImageUtil.saveBitmap(dst); dst.recycle(); //Maybe reuse it will be better. diff --git a/library/src/main/jni/interface/cgeImageHandlerAndroid.cpp b/library/src/main/jni/interface/cgeImageHandlerAndroid.cpp index ff218397..8ec51721 100644 --- a/library/src/main/jni/interface/cgeImageHandlerAndroid.cpp +++ b/library/src/main/jni/interface/cgeImageHandlerAndroid.cpp @@ -95,6 +95,12 @@ bool CGEImageHandlerAndroid::initWithBitmap(JNIEnv* env, jobject bmp, bool enabl jobject CGEImageHandlerAndroid::getResultBitmap(JNIEnv* env) { + if(m_dstImageSize.width <= 0 || m_dstImageSize.height <= 0) + { + CGE_LOG_ERROR("Invalid image size!"); + return nullptr; + } + jclass bitmapCls = env->FindClass("android/graphics/Bitmap"); jmethodID createBitmapFunction = env->GetStaticMethodID(bitmapCls, "createBitmap", "(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");