diff --git a/photoeditor/src/main/java/ja/burhanrashid52/photoeditor/PhotoEditor.java b/photoeditor/src/main/java/ja/burhanrashid52/photoeditor/PhotoEditor.java index b7ea7282..8c157302 100644 --- a/photoeditor/src/main/java/ja/burhanrashid52/photoeditor/PhotoEditor.java +++ b/photoeditor/src/main/java/ja/burhanrashid52/photoeditor/PhotoEditor.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.Canvas; import android.graphics.Typeface; import android.os.AsyncTask; import androidx.annotation.ColorInt; @@ -653,7 +654,6 @@ public void onBitmapReady(Bitmap saveBitmap) { protected void onPreExecute() { super.onPreExecute(); clearHelperBox(); - parentView.setDrawingCacheEnabled(false); brushDrawingView.destroyDrawingCache(); } @@ -665,11 +665,10 @@ protected Exception doInBackground(String... strings) { try { FileOutputStream out = new FileOutputStream(file, false); if (parentView != null) { - parentView.setDrawingCacheEnabled(true); - Bitmap drawingCache = saveSettings.isTransparencyEnabled() - ? BitmapUtil.removeTransparency(parentView.getDrawingCache()) - : parentView.getDrawingCache(); - drawingCache.compress(saveSettings.getCompressFormat(), saveSettings.getCompressQuality(), out); + Bitmap capturedBitmap = saveSettings.isTransparencyEnabled() + ? BitmapUtil.removeTransparency(captureView(parentView)) + : captureView(parentView); + capturedBitmap.compress(saveSettings.getCompressFormat(), saveSettings.getCompressQuality(), out); } out.flush(); out.close(); @@ -733,17 +732,15 @@ public void onBitmapReady(Bitmap saveBitmap) { protected void onPreExecute() { super.onPreExecute(); clearHelperBox(); - parentView.setDrawingCacheEnabled(false); brushDrawingView.destroyDrawingCache(); } @Override protected Bitmap doInBackground(String... strings) { if (parentView != null) { - parentView.setDrawingCacheEnabled(true); return saveSettings.isTransparencyEnabled() ? - BitmapUtil.removeTransparency(parentView.getDrawingCache()) - : parentView.getDrawingCache(); + BitmapUtil.removeTransparency(captureView(parentView)) + : captureView(parentView); } else { return null; } @@ -781,6 +778,17 @@ private static String convertEmoji(String emoji) { return returnedEmoji; } + private Bitmap captureView(View view) { + Bitmap bitmap = Bitmap.createBitmap( + view.getWidth(), + view.getHeight(), + Bitmap.Config.ARGB_8888 + ); + Canvas canvas = new Canvas(bitmap); + view.draw(canvas); + return bitmap; + } + /** * Callback on editing operation perform on {@link PhotoEditorView} *