Mögliche Duplizieren:
Converting a view to Bitmap without displaying it in Android?convert Blick in Bitmap
Ich versuche, den Blick in Bitmap
nun aus folgenden Referenz Link zu konvertieren das Problem Wie kann ich die Bitmap erhalten, von der konvertiert wird? Nur ansehen. im Beispiel Autor hat relativelayout.dispatchDraw (c), aber diese Linie gibt mir Fehler dh
Verfahren dispatchDraw (Leinwand) von der Typ Viewgroup nicht sichtbar kompilieren Zeit verwendet
ist
Hier mein Code, und ich habe den folgenden Code innerhalb onCreate Funktion geschrieben
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);
Hier die returnedBitmap das Bild (Image und Textview), aber das Bitmap enthält nur bacground Bitmap von relati enthalten sollte veView heißt bgblack
Ich hatte das gleiche Problem früher und fand keine Lösung, auch. Jemand hat mir gesagt, dass der Zeichencache ein Punkt sein kann. Aber ich konnte es nicht richtig machen. – Impression
Ich weiß nicht, wie Draw Cache – Hunt
zu verwenden, wenn ich relativeView.setDrawingCacheEnabled (true) verwenden; und danach, wenn ich versuchen werde, den Cache mit relativerView.getDrawingCache() zu bekommen, bekomme ich null Bitmap – Hunt