我想在活動中拍攝一張照片並分享此照片。 首先,我用這個方法:如何在Android上拍攝一個視圖的屏幕快照?
private Bitmap getShareViewShot() {
this.setDrawingCacheEnabled(true);
this.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(this.getDrawingCache(), 0, mSharePageRoot.getTop(), this.getWidth(), mSharePageRoot.getBottom());
this.setDrawingCacheEnabled(false);
return bitmap;
}
但是,如果認爲是在一個滾動型和觀點滾動屏幕外,這種方法不能得到這種觀點的全貌。
所以我改變這個方法如下:
private Bitmap getShareViewShot() {
Bitmap bitmap = Bitmap.createBitmap(mSharePageRoot.getWidth(), mSharePageRoot.getHeight(),
Bitmap.Config.ARGB_8888);
mSharePageRoot.layout(0, 0, mSharePageRoot.getLayoutParams().width, mSharePageRoot.getLayoutParams().height);
final Canvas canvas = new Canvas(bitmap);
mSharePageRoot.draw(canvas);
return bitmap;
}
但另一個問題來了:這種觀點有沒有研究背景,所以我得到的圖片有一個黑色backgroud.In我的代碼,該活動有一個網絡形象作爲背景,所以這意味着這種方法無法得到活動的背景。
請原諒我的壞英語。 有沒有其他方法?謝謝。
https://stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-in -android?rq = 1 –
http://stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-in-android –