Hi all,
I use below codes to generate the bitmap of a view:
view.measure(MeasureSpec.makeMeasureSpec(0,
MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(),
view.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
view.getHeight(),
Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
However, when the view really displays, it looks quite different with the
bitmap that I get. Please see below two snapshots.
*Below is the bitmap that I generated:*
<https://lh5.googleusercontent.com/-7tOJkO961Es/UFc3XjIvrFI/AAAAAAAAAGU/vXNeEPF-xyY/s1600/bitmap.png>
*Below is the view's real display:*
<https://lh5.googleusercontent.com/-x76-haIiBOI/UFc3gTBYTnI/AAAAAAAAAGc/b5dkPTrLlNk/s1600/view.png>
*Below is the layout of this view:*
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:id="@+id/btnTest"/>
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ivTest"/>
</LinearLayout>
However, the above method is searched and got from stackoverflow. So I
assume it should work. Can someone tell me why the bitmap that I get is
different with the real display and how to resolve it? Thanks in advance.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en