Gaëtan Renaudeau пре 8 година
родитељ
комит
12b23da501
2 измењених фајлова са 18 додато и 2 уклоњено
  1. 0
    1
      README.md
  2. 18
    1
      android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java

+ 0
- 1
README.md Прегледај датотеку

@@ -48,7 +48,6 @@ Snapshots are not guaranteed to be pixel perfect. It also depends on the platfor
48 48
 - Support of special components like Video / GL views remains untested.
49 49
 - It's preferable to **use a background color on the view you rasterize** to avoid transparent pixels and potential weirdness that some border appear around texts.
50 50
 - on Android, you need to make sure `collapsable` is set to `false` if you want to snapshot a **View**. Otherwise that view won't reflect any UI View. ([found by @gaguirre](https://github.com/gre/react-native-view-shot/issues/7#issuecomment-245302844))
51
-- on Android, you can't snapshot a big view. The limit looks like to be set to your screen size (number of pixels).
52 51
 
53 52
 ## Getting started
54 53
 

+ 18
- 1
android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java Прегледај датотеку

@@ -2,6 +2,7 @@ package fr.greweb.reactnativeviewshot;
2 2
 
3 3
 import javax.annotation.Nullable;
4 4
 import android.graphics.Bitmap;
5
+import android.graphics.Canvas;
5 6
 import android.net.Uri;
6 7
 import android.util.Base64;
7 8
 import android.view.View;
@@ -103,6 +104,16 @@ public class ViewShot implements UIBlock {
103 104
         }
104 105
     }
105 106
 
107
+    public static Bitmap loadBitmapFromView(View v)
108
+    {
109
+        Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
110
+
111
+        Canvas c = new Canvas(b);
112
+        v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
113
+        v.draw(c);
114
+        return b;
115
+    }
116
+
106 117
     /**
107 118
      * Screenshot a view and return the captured bitmap.
108 119
      * @param view the view to capture
@@ -114,10 +125,16 @@ public class ViewShot implements UIBlock {
114 125
         if (w <= 0 || h <= 0) {
115 126
             throw new RuntimeException("Impossible to snapshot the view: view is invalid");
116 127
         }
128
+        /*
117 129
         if (!view.isDrawingCacheEnabled())
118 130
           view.setDrawingCacheEnabled(true);
119 131
 
120 132
         Bitmap bitmap = view.getDrawingCache();
133
+        */
134
+        Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
135
+        Canvas c = new Canvas(bitmap);
136
+        view.layout(0, 0, view.getLayoutParams().width, view.getLayoutParams().height);
137
+        view.draw(c);
121 138
 
122 139
         if (width != null && height != null && (width != w || height != h)) {
123 140
             bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
@@ -126,6 +143,6 @@ public class ViewShot implements UIBlock {
126 143
             throw new RuntimeException("Impossible to snapshot the view");
127 144
         }
128 145
         bitmap.compress(format, (int)(100.0 * quality), os);
129
-        view.setDrawingCacheEnabled(false);
146
+        //view.setDrawingCacheEnabled(false);
130 147
     }
131 148
 }