プログラムで電話画面をキャプチャする方法を知りたいです。私はちょうどグーグルで、view.getDrawingCache()を使用しなければならないことを知りました。ただし、getDrawingCache() は常に null を返します。
私のxmlレイアウトは
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/screenlayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/screen"
/>
</LinearLayout>
ジャバファイル::
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View vScreen = findViewById(R.id.screenlayout);
ImageView imageview = (ImageView)findViewById(R.id.screen);
Bitmap bitmap;
View v1 = vScreen.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache()); //getting null here
v1.setDrawingCacheEnabled(false)
imageview.setImageBitmap(bitmap);
}
誰かが私が間違っているところを修正してもらえますか?