Bonjour
J'ai une application qui affiche en fond la camera sur un RelativeLayout avec des composants par-dessus l'image. Je souhaiterais pouvoir capturer avec un screenshot le total de l’écran en cours.
Mon problème est que, dans la capture, l'image de la preview est noire mais j'ai bien mes composants.
Y-a-t'il une possibilité de capturer la preview + les widgets. ?
J'ai testé différentes explications et m'adresse à vous maintenant.
Je vous remercie d'avance.
voici ma méthode de capture:
voici ma méthode de sauvegarde:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 private static Bitmap takeScreenShot(Activity activity) { View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap b1 = view.getDrawingCache(); Rect frame = new Rect(); activity.getWindow().getDecorView().getDrawingCache(); //getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay().getHeight(); Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); return b; }
merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 private void saveBitmap(Bitmap bitmap) { Date d=new Date(); String fileName = d.getTime()+"mg1.jpg"; File storagePath = (Environment.getExternalStorageDirectory()); File dest = new File(storagePath + "/DashCamApp"); if (!dest.exists()) { dest.mkdirs(); } File mFile2 = new File(dest, fileName); try { FileOutputStream outStream; outStream = new FileOutputStream(mFile2); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, outStream); outStream.flush(); outStream.close(); Toast.makeText(this, "Photo Saved Sucessfully", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(this, "Photo Not Saved Sucessfully", Toast.LENGTH_SHORT).show(); } }
Partager