2

背景として設定された MapView からの別のビットマップと、右隅にある他の 2 つのビュー (アイコンとテキスト) を含む RelativeLayout からビットマップを作成しています。必要な画像を取得していますが、低品質です。私は高低を検索し、ビューをビットマップに変換することに関する多くのページを見つけましたが、品質に関するものは何も見つかりませんでした. スケーリングと関係があるのではないかと思います。

出力画像:

出力画像の低品質

コード:

public Bitmap getBitmapFromMapView() {
    // Get Bitmap from MapView
    Bitmap mapBitmap = Bitmap.createBitmap(mMapView.getWidth(), mMapView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas mapCanvas = new Canvas(mapBitmap);
    mMapView.draw(mapCanvas);

    // Inflate RelativeLayout view containing ImageView (FlagIt icon) and TextView (URL) in bottom-right corner
    // and merge it with the MapView Bitmap to produce an Overall Bitmap containing everything
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    RelativeLayout overallRelativeLayout = (RelativeLayout) inflater.inflate(R.layout.screenshot, null);
    overallRelativeLayout.setBackgroundDrawable(new BitmapDrawable(mapBitmap));

    overallRelativeLayout.measure(
            MeasureSpec.makeMeasureSpec(mMapView.getWidth(), MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(mMapView.getHeight(), MeasureSpec.EXACTLY));
    overallRelativeLayout.layout(0, 0, overallRelativeLayout.getMeasuredWidth(), overallRelativeLayout.getMeasuredHeight());

    Bitmap overallBitmap = Bitmap.createBitmap(mMapView.getWidth(), mMapView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas overallCanvas = new Canvas(overallBitmap);
    overallRelativeLayout.draw(overallCanvas);


    return overallBitmap;
}

および膨張した screenshot.xml XML ファイル:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/screenshot_corner_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="4dip"
        android:layout_marginRight="4dip"
        android:shadowColor="#000000"
        android:shadowDx="0.0"
        android:shadowDy="0.0"
        android:shadowRadius="4"
        android:text="http://www.aroha.ws"
        android:textColor="#ff0000"
        android:textSize="18sp"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/screenshot_corner_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/screenshot_corner_text"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="4dip"
        android:layout_marginRight="4dip"
        android:src="@drawable/corner_title_icon" />

</RelativeLayout>

私の画面に表示されたときの RelativeLayout は、より良い品質に見えます:

出力画像の望ましい品質

4

0 に答える 0