次の参照リンクからビューをビットマップに変換しようとしています
今問題は、ビューのみから変換されているビットマップを取得する方法です。この例では、著者はrelativelayout.dispatchDraw(c)を使用していますが、この行はコンパイル時エラーを引き起こしています。
タイプ ViewGroup のメソッド dispatchDraw(Canvas) が表示されない
ここに私のコードがあり、 onCreate 関数内に次のコードを書きました
Canvas c=null;
//Create Layout
RelativeLayout relativeView ;
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT
);
relativeView = new RelativeLayout(this);
relativeView.setLayoutParams(lp);
//Background of Layout
Bitmap viewBgrnd = BitmapFactory.decodeResource(getResources(),R.drawable.bgblack);
relativeView.setBackgroundDrawable(new BitmapDrawable(viewBgrnd));
//associated with canvas
Bitmap returnedBitmap = Bitmap.createBitmap(320,480,Bitmap.Config.ARGB_8888);
c = new Canvas(returnedBitmap);
Paint paint = new Paint();
//Create Imageview that holds image
ImageView newImage = new ImageView(this);
Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.bgpink);
newImage.setImageBitmap(srcBitmap);
TextView newText = new TextView(this);
newText.setText("This is the text that its going to appear");
c.drawBitmap(viewBgrnd, 0, 0, paint);
relativeView.layout(100, 0, 256, 256);
relativeView.addView(newImage);
relativeView.addView(newText);
// here i am getting compile time error so for timing i have replaced this line
// with relativeView.draw(c);
relativeView.dispatchDraw(c);
ここで、returnedBitmap には (ImageView および TextView) のイメージが含まれている必要がありますが、このビットマップには、relativeView の bacground ビットマップ、つまり bgblack のみが含まれています。