Duplicar posibles:
Converting a view to Bitmap without displaying it in Android?presentación convertida en mapa de bits
Estoy tratando de convertir la visión en mapa de bits de enlace siguiente referencia
Ahora el problema ¿Cómo puedo obtener el mapa de bits que se está convirtiendo de sólo vista. en el ejemplo de autor ha utilizado relativelayout.dispatchDraw (c) pero esta línea está dando me Error de compilación tiempo, es decir
El método dispatchDraw (Canvas) de el tipo ViewGroup no es visible
Aquí está mi código y he escrito el siguiente código dentro de la función 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);
Aquí el returnedBitmap debe contener la imagen de (ImageView y TextView), pero este mapa de bits de mapa de bits contiene sólo fundamento de la relati veView decir bgblack
que tenía el mismo problema tiempos pasados y no encontró ninguna solución, también. Alguien me dijo que el caché de dibujo puede ser un punto. Pero no pude hacerlo funcionar de la manera correcta. – Impression
No sé cómo usar draw cache – Hunt
si uso relativeView.setDrawingCacheEnabled (true); y después de eso si trataré de obtener el caché usando relativeView.getDrawingCache() obtendré un mapa de bits nulo – Hunt