I want to extract following part of 'display' as an image to a PNG file.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/Layout">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/Image_view"
/>
<TextView
android:id="@+id/text_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</FrameLayout>
</LinearLayout>
To do that, I use following code
list.add("Raghul s");
list.add("Name 2");
list.add("Name 3");
for(int i=0;i<list.size();i++)
{
LinearLayout view = (LinearLayout) findViewById(R.id.Layout);
txt = (TextView) findViewById(R.id.Text_View1);
txt.setText(list.get(i));
view.setDrawingCacheEnabled(true);
view.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
bs = new ByteArrayOutputStream();
bs.compress(Bitmap.CompressFormat.PNG, 40, bitmap);
try {
file = new File("Image.png");
file.createNewFile();
ws = new FileOutputStream(file);
ws.write(bs.toByteArray());
ws.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
When I execute this code, I obtain an PGN image where Raghul s word is partially truncated as in the following image
What is happening ?
Why "Raghul s" and "name 2" are truncated ?
How to solve this issue ?