解决方法
好的,这个有点棘手.据我所知,没有直接的方法去做.这是有用的东西.我试图拍摄单独的照片并分层.
Dialog dialog = // Dialog that is showing View mainView = getSupportActivity().getWindow().getDecorView(); mainView = getSupportActivity().getWindow().getDecorView() .findViewById(android.R.id.content); mainView.setDrawingCacheEnabled(true); // This is the bitmap for the main activity Bitmap bitmap = mainView.getDrawingCache(); View dialogView = dialog.getView(); int location[] = new int[2]; mainView.getLocationOnScreen(location); int location2[] = new int[2]; dialogView.getLocationOnScreen(location2); dialogView.setDrawingCacheEnabled(true); // This is the bitmap for the dialog view Bitmap bitmap2 = dialogView.getDrawingCache(); Canvas canvas = new Canvas(bitmap); // Need to draw the dialogView into the right position canvas.drawBitmap(bitmap2,location2[0] - location[0],location2[1] - location[1],new Paint()); String filename = // filename to save File myPath = new File(filename); FileOutputStream fos = null; try { fos = new FileOutputStream(myPath); bitmap.compress(Bitmap.CompressFormat.PNG,100,fos); fos.flush(); fos.close(); Trace.d("Twitter","The file path is " + myPath); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }
我只是试过了,它的工作.希望这可以帮助.让我知道如果不行.