| 
				
			 | 
			
			
				@@ -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
			 | 
			
			
				 } 
			 |