-1
私の問題は、このコードの出力は私が期待していたものではなく、これ(正方形)です。これがどうして起こるのか?フォアグラウンドのスクリーンショットを撮ろうとしているときに出力が予期しないです
出力は基本的に画像のような正方形ではありませんが、実際には正方形ではありませんが、すべてのビューが含まれていますが、これは圧縮されています。適切な場所:
コード:
private Bitmap getScreenshot(int id) {
Log.d(TAG, "Creating screenshot");
RelativeLayout RL= (RelativeLayout)findViewById(id);
View v1 = getWindow().getDecorView().getRootView(); //or RL.getRootView();
v1.setDrawingCacheEnabled(true);
v1.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v1.layout(0, 0, v1.getMeasuredWidth(), v1.getMeasuredHeight());
v1.buildDrawingCache(true);
Bitmap bm = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
return bm;
}
画像:
となります。私は唯一の絶望的な管理者です。リンク:https://www.pixeldroidof.net/qcode.txt –
http://stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-in-android/5651242#5651242これを確認してください2つのリンク http://stackoverflow.com/questions/32624133/how-to-take-a-screen-shot-on-a-button-click-can-anyone-provide-a-android-code/32624305#32624305 –
タイトルバーのないスクリーンショットが必要な場合はこちらをチェックしてください。http://stackoverflow.com/a/30212385/7320259 –