mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 13:51:27 +08:00

committed by
Nathan Walker

parent
dbaf203a59
commit
9b5d125f42
Binary file not shown.
@ -1060,12 +1060,11 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
|
||||
// view.layout(0, 0, width, height);
|
||||
// view.draw(canvas);
|
||||
|
||||
view.setDrawingCacheEnabled(true);
|
||||
const drawCache = view.getDrawingCache();
|
||||
const bitmap = android.graphics.Bitmap.createBitmap(drawCache);
|
||||
view.setDrawingCacheEnabled(false);
|
||||
|
||||
return bitmap;
|
||||
// view.setDrawingCacheEnabled(true);
|
||||
// const drawCache = view.getDrawingCache();
|
||||
// const bitmap = android.graphics.Bitmap.createBitmap(drawCache);
|
||||
// view.setDrawingCacheEnabled(false);
|
||||
return org.nativescript.widgets.Utils.getBitmapFromView(view);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -633,6 +633,7 @@ declare module org {
|
||||
export module widgets {
|
||||
export class Utils {
|
||||
public static class: java.lang.Class<org.nativescript.widgets.Utils>;
|
||||
public static getBitmapFromView(param0: globalAndroid.view.View): globalAndroid.graphics.Bitmap;
|
||||
public static loadImageAsync(param0: globalAndroid.content.Context, param1: string, param2: string, param3: number, param4: number, param5: org.nativescript.widgets.Utils.AsyncImageCallback): void;
|
||||
public static drawBoxShadow(param0: globalAndroid.view.View, param1: string): void;
|
||||
public static saveToFileAsync(param0: globalAndroid.graphics.Bitmap, param1: string, param2: string, param3: number, param4: org.nativescript.widgets.Utils.AsyncImageCallback): void;
|
||||
|
@ -33,6 +33,11 @@ import java.io.IOException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
public class Utils {
|
||||
public static Drawable getDrawable(String uri, Context context) {
|
||||
@ -51,6 +56,42 @@ public class Utils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap drawBitmap(View view) {
|
||||
int width = view.getWidth();
|
||||
int height = view.getHeight();
|
||||
Bitmap bitmap;
|
||||
if (view.getAlpha() < 1F) {
|
||||
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
} else {
|
||||
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
|
||||
}
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
if (!ViewCompat.isLaidOut(view)) {
|
||||
view.layout(0, 0, width, height);
|
||||
}
|
||||
view.draw(canvas);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static Bitmap getBitmapFromView(View view) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
return drawBitmap(view);
|
||||
} else {
|
||||
|
||||
view.setDrawingCacheEnabled(true);
|
||||
Bitmap drawCache = view.getDrawingCache();
|
||||
Bitmap bitmap = Bitmap.createBitmap(drawCache);
|
||||
view.setDrawingCacheEnabled(false);
|
||||
|
||||
if (bitmap == null) {
|
||||
bitmap = drawBitmap(view);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawBoxShadow(View view, String value) {
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
|
||||
return;
|
||||
|
Reference in New Issue
Block a user