This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] - snapshot bitmap contains view based content (#9252)
- Loading branch information
Showing
2 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...form/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.mapbox.mapboxsdk.utils; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.Canvas; | ||
import android.support.annotation.NonNull; | ||
import android.view.View; | ||
|
||
public class BitmapUtils { | ||
|
||
public static Bitmap createBitmapFromView(@NonNull View view) { | ||
view.setDrawingCacheEnabled(true); | ||
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); | ||
view.buildDrawingCache(); | ||
|
||
if (view.getDrawingCache() == null) { | ||
return null; | ||
} | ||
|
||
Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache()); | ||
view.setDrawingCacheEnabled(false); | ||
view.destroyDrawingCache(); | ||
return snapshot; | ||
} | ||
|
||
public static Bitmap mergeBitmap(@NonNull Bitmap background, @NonNull Bitmap foreground) { | ||
Bitmap result = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig()); | ||
Canvas canvas = new Canvas(result); | ||
canvas.drawBitmap(background, 0f, 0f, null); | ||
canvas.drawBitmap(foreground, 10, 10, null); | ||
return result; | ||
} | ||
|
||
} |