I am trying to convert an XML Layout to an JPEG image. (This can be
helpful in many ways: for example - using in-built rendering engine's
capability to center crop an image by having an ImageView in an
AbsoluteLayout as shown below.)


<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
        xmlns:android="http://schemas.android.com/apk/res/android";
        android:id="@+id/al44"
        android:orientation="vertical"
        android:layout_width="320px"
        android:layout_height="480px">

<ImageView
        android:id="@+id/image1"
        android:layout_width="320px"
        android:layout_height="480px"
        android:layout_x="0px"
        android:layout_y="0px"
        android:scaleType="centerCrop"
        android:src="@drawable/centred"
        />
</AbsoluteLayout>

I use the following code to do this, but all I get is a blank image.
Any suggestions?

Bitmap targetBitmap = Bitmap.createBitmap(320, 480,
Bitmap.Config.RGB_565);
Canvas drawingCanvas = new Canvas(targetBitmap);
AbsoluteLayout al = (AbsoluteLayout)View.inflate(this,
R.layout.my_image, null);
al.draw(drawingCanvas);
FileOutputStream fos = this.openFileOutput("result.jpg",
MODE_WORLD_READABLE);
targetBitmap.compress(Bitmap.CompressFormat.JPEG, 75, fos);
fos.flush();
fos.close();

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to