Skip to content

Commit

Permalink
Merge pull request #526 from wysaid/fix_#524
Browse files Browse the repository at this point in the history
fix crash: #524
  • Loading branch information
wysaid authored Nov 21, 2023
2 parents 61beec3 + 4b927de commit 617507a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
10 changes: 9 additions & 1 deletion cgeDemo/src/main/java/org/wysaid/cgeDemo/ImageDemoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions library/src/main/jni/interface/cgeImageHandlerAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;");
Expand Down

0 comments on commit 617507a

Please sign in to comment.