From fa3ced9f3a5be3731b17c2af899c9328250edddd Mon Sep 17 00:00:00 2001 From: "sungmin.jung" Date: Wed, 10 Mar 2021 11:01:12 +0900 Subject: [PATCH] Replace deprecated `getDrawingCache` to capturing method. - getDrawingCache is deprecated. - getDrawingCache raises #284 - PixelCopy is better way. But it needs window instance. --- .../photoeditor/PhotoEditor.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) 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} *