0

在我的应用程序中,我在单个活动中获得了三个自定义视图。所以现在我需要将它保存为单个 jpeg。如何实现这一点。我知道如何保存一个或两个位图,但这次是在单个活动中保存三个自定义视图。

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<com.wglxy.example.pinchzoompan.PanZoomView
android:id="@+id/zoomview1"
android:layout_width="100dp"
android:layout_height="700dp"
/>
<com.wglxy.example.pinchzoompan.PanZoomView1
android:id="@+id/zoomview2"
android:layout_width="100dp"
android:layout_height="700dp"
/>
<com.wglxy.example.pinchzoompan.PanZoomView2
android:id="@+id/zoomview3"
android:layout_width="100dp"
android:layout_height="700dp"
/>

</LinearLayout>
</FrameLayout>

每个视图都有一张图片,现在我需要将其保存为单个 jpeg。谁能给我一些想法。

4

3 回答 3

0

使用 layoutinflater 将您的 xml 膨胀为单个视图,然后创建该视图的位图。

于 2013-08-01T11:25:05.457 回答
0

我使用此代码将我的三个视图保存为单个 jpeg 文件

 layout = (LinearLayout) findViewById(R.id.viewLayout);
            layout.setDrawingCacheEnabled(true);
            layout.buildDrawingCache();
            viewbitmap = layout.getDrawingCache(true);

接着

try {
             viewbitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(f));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }           
于 2013-08-01T12:10:41.823 回答
0

只需将所有子项放在父布局中,然后为该父视图设置DrwaingCache true ,之后每当您需要在该父视图上获取或保存所有子视图时,您都可以为该父视图获取DrawingCache。

于 2013-10-10T07:36:39.913 回答