1

アプリケーションに(地図の)画像を入れて、その上にプログラムでいくつかのレイヤー(プレースホルダー、パスなど)を追加したいのですが、フォトショップのようなレイヤーアプローチが役立つと思いますが、私はどこから始めればいいのかわからない。チュートリアルまたはドキュメントへの簡単な例/リンクが役立ちます:)

ありがとう

4

1 に答える 1

2

私はあなたが構築できる簡単なアプローチをあなたに与えています:

  • 空のビットマップを作成しますfinalBitmap。これは、すべてのレイヤー構成の最終的な宛先になります。
  • Canvasに描画するを作成しますfinalBitmap。このキャンバスは、すべてのレイヤーを最終的なビットマップに描画するために使用されます。
  • Bitmapマップ画像を使用してを作成します。finalBitmapキャンバスを使用して描画します。これはレイヤー1になります。
  • 同じアプローチを使用して、マーカーやルートなどを配置します。それらはレイヤー2、3などになります。

例のコード:

//The empty Bitmap
finalBitmap = Bitmap.createBitmap(width, height , Bitmap.Config.ARGB_8888);
canvas = new Canvas(finalBitmap );
imageView.setImageBitmap(finalBitmap );


//Create the map image bitmap
Config config = Config.RGB_565;
Options options = new Options();
options.inPreferredConfig = config;
InputStream in = null;
Bitmap bitmap = null;
try {
        in = new FileInputStream(fMapImage);
        bitmap = BitmapFactory.decodeStream(in);
        if (bitmap == null)
            throw new RuntimeException("Couldn't load bitmap from asset :" + fMapImage.getAbsolutePath());
    } catch (IOException e) {
        throw new RuntimeException("Couldn't load bitmap from asset :" + fMapImage.getAbsolutePath());
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
            }
        }
}


//Draw the map image bitmap
Rect dst = new Rect(pt00.x, pt00.y, ptMM.x, ptMM.y);
canvas.drawBitmap(bitmap, null, dst, null);

//Here draw whatever else you want (markers, routes, etc.)

よろしく

于 2012-12-09T19:48:02.437 に答える