Hi, thanks a lot for your answer, it's helping a lot.
Last but not least I've got some differences on two real devices. First of all the XML: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#fff"> <TextView android:id="@+id/tv" android:layout_width="340px" android:layout_height="71px" android:text="The Quick Brown Fox..." android:textSize="20px" android:background="#abcdef" android:textColor="#000" android:layout_marginBottom="20dip" /> <ImageView android:id="@+id/iv" android:layout_width="340px" android:layout_height="71px" android:background="#56789a" /> </LinearLayout> Now the new code: Bitmap bmp = Bitmap.createBitmap(340, 71, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); TextView tv = new TextView(this); tv.setText("The Quick Brown Fox..."); tv.setTextSize(20.0f); tv.setBackgroundColor(Color.rgb(0xab, 0xcd, 0xef)); tv.setTextColor(Color.rgb(0x00, 0x00, 0x00)); tv.measure(340, 71); // !!! tv.layout(0, 0, 340, 71); // !!! tv.draw(canvas); ImageView iv = (ImageView) findViewById(R.id.iv); iv.setImageBitmap(bmp); On a HTC Magic (320x480) both views are the same. On a Nexus S the ImageView with the Bitmap with the TextView is much bigger than the pure TextView one. So I think it is a density isue. As the doc says the createBitmap already takes care of the Density. Playing with the factor 1.5 (= 240dpi / 160dpi) didn't help me out. Here are 2 links: http://webinmotion.de/android/masc/Magic.png http://webinmotion.de/android/masc/NexusS.png Best regards, Marco 2011/9/4 Romain Guy <romain...@android.com> > You didn't give your TextView a size. You must first call measure(), then > layout(), then you can draw the view. > > On Sun, Sep 4, 2011 at 2:43 AM, Marco Alexander Schmitz < > marco.alexander.schm...@googlemail.com> wrote: > >> hi, >> >> many posts are found according to the topic "screenshot a TextView >> into a Bitmap". >> >> Well, the difference to my problem is, that first the view is drawn on >> the display (with all layouting and measuring work already done) and >> then drawn into a Canvas connected to a Bitmap. >> >> I just want to create a TextView from scratch without ever beeing >> shown on the display which is rendered into a Bitmap. >> >> --- cut --- cut --- cut --- cut --- cut --- cut --- cut --- cut --- >> cut --- cut --- cut --- cut --- cut --- cut --- cut --- cut --- cut >> --- >> >> This one is the basis configuration which is already workin. A click >> on the TextView draws itself into a Bitmap and sets it to an >> ImageView. >> >> <?xml version="1.0" encoding="utf-8"?> >> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ >> android" >> android:layout_width="fill_parent" >> android:layout_height="fill_parent" >> android:orientation="vertical" android:background="#fff"> >> >> <TextView android:id="@+id/tv" android:layout_width="wrap_content" >> android:layout_height="wrap_content" android:text="The >> Quick Brown >> Fox Jumps Over The Lazy Dog." >> android:textSize="20dip" android:background="#abcdef" >> android:textColor="#000" android:padding="10dip" >> android:layout_margin="10dip" /> >> >> <ImageView android:id="@+id/iv" android:layout_width="449px" >> android:layout_height="47px" android:background="#56789a" >> android:layout_margin="10dip" /> >> </LinearLayout> >> >> public class WorkingActivity extends Activity { >> >> @Override >> public void onCreate(Bundle savedInstanceState) { >> super.onCreate(savedInstanceState); >> setContentView(R.layout.main); >> >> findViewById(R.id.tv).setOnClickListener(new OnClickListener() >> { >> >> @Override >> public void onClick(View v) { >> Bitmap bmp = Bitmap.createBitmap(449, 47, >> Bitmap.Config.ARGB_8888); >> Canvas canvas = new Canvas(bmp); >> >> v.draw(canvas); >> >> ImageView iv = (ImageView) findViewById(R.id.iv); >> iv.setImageBitmap(bmp); >> } >> }); >> } >> } >> >> --- cut --- cut --- cut --- cut --- cut --- cut --- cut --- cut --- >> cut --- cut --- cut --- cut --- cut --- cut --- cut --- cut --- cut >> --- >> >> Now comes the problematic part. I will create a TextView in Java and I >> want this one to be drawn straight into a Bitmap. After this I will >> set this to an ImageView. I never got this running :( >> >> Bitmap bmp = Bitmap.createBitmap(449, 47, >> Bitmap.Config.ARGB_8888); >> Canvas canvas = new Canvas(bmp); >> >> TextView tv = new TextView(this); >> tv.setText("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"); >> tv.setTextSize(55f); >> >> tv.setTextColor(this.getResources().getColor(android.R.color.black)); >> tv.draw(canvas); >> >> ImageView iv = (ImageView) findViewById(R.id.iv); >> iv.setImageBitmap(bmp); >> >> This doesn't work neither in onCreate nor in a OnClickListener. >> Experimenting with setDrawingCacheEnabled(), measure() and >> requestLayout() didn't work, too... >> >> Can you help me please on this? >> >> Greetings, >> Marco >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to android-developers@googlegroups.com >> To unsubscribe from this group, send email to >> android-developers+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > > > -- > Romain Guy > Android framework engineer > romain...@android.com > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en