Skip to content

Commit

Permalink
Replace deprecated getDrawingCache to capturing method.
Browse files Browse the repository at this point in the history
- getDrawingCache is deprecated.
- getDrawingCache raises #284
- PixelCopy is better way. But it needs window instance.
  • Loading branch information
JSpiner authored and burhanrashid52 committed Mar 13, 2021
1 parent f68da2a commit fa3ced9
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -653,7 +654,6 @@ public void onBitmapReady(Bitmap saveBitmap) {
protected void onPreExecute() {
super.onPreExecute();
clearHelperBox();
parentView.setDrawingCacheEnabled(false);
brushDrawingView.destroyDrawingCache();
}

Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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}
*
Expand Down

0 comments on commit fa3ced9

Please sign in to comment.