Reputation:
I want to convert my layout that contains images,text to bitmap to implement pagecurl effect in my app..
My xml is
details.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background= "#E0FFFF"
android:gravity="center"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/framelayout"
android:layout_marginTop="30dip"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/Rl">
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="60dip"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="BookName"
android:textSize="40dip"
android:textStyle="bold" />
<TextView
android:id="@+id/tTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tvName"
android:text="Page Name"
android:textColor="#040404"
android:textSize="30dip"
android:textStyle="bold"
android:typeface="sans" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="false"
android:layout_below="@id/tTitle"
android:baselineAlignBottom="true"
android:scaleType="fitXY"
android:src="@drawable/stub"
android:id="@+id/smallImage"
/>
<TextView
android:id="@+id/tDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dip"
android:layout_below="@id/smallImage" />
<Button
android:id="@+id/buy_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/tTitle"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="22dp"
android:text="buy"
android:visibility="visible"/>
<Button
android:id="@+id/bLib"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tDescription"
android:text="Go to Library"
android:textSize="20dip"
android:textStyle="italic"
/>
<Button
android:id="@+id/backD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/bLib"
android:layout_alignParentRight="true"
android:layout_below="@id/tDescription"
android:text="Back to Home"
android:textStyle="bold"
android:textSize="20dip"
/>
</RelativeLayout>
</FrameLayout>
</ScrollView>
and my java class to convert this layout to bitmap is
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
FrameLayout view = (FrameLayout)findViewById(R.id.framelayout);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bm = view.getDrawingCache();
System.err.println("getting bitmap.."+bm);
}
I am not finding the way to set the layout values here..Here i am getting bitmap bm value as null.Could anyone suggest me how to convert that layout in bitmap and set those values to bitmap?
Upvotes: 2
Views: 1969
Reputation: 3417
to overcome with this problem I destroy the drawingcache after saving the bitmap.
view.destroyDrawingCache();
and save your bitmap as per below code.
view.measure(100, 100);
view.layout(0, 0, 100, 100);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b = Bitmap.createBitmap(view.getDrawingCache());
Upvotes: 1
Reputation: 7754
Check if the it is going out of memory while getting the bitmap.
Put
try
{....}
catch(OutOfMemoryException ex)
{}
Another problem can be this: Your view is not drawn when you are taking the bitmap. Try using button onclick function to do the same procedure.
Upvotes: 0