【问题标题】:How to overlay jpg file as bitmap file on mapview in osmdroid如何在osmdroid的mapview上将jpg文件叠加为位图文件
【发布时间】:2019-08-23 14:49:14
【问题描述】:

我使用 osmdroid 和 first 方法在地图上显示了一张照片。 现在我想从设备内存中读取一张 jpeg 格式的图片,并将其显示为地图上的位图。该代码没有给出错误。但是照片没有显示。请指导我。以下是第一种和第二种方法代码。

/// first method
GroundOverlay myGroundOverlay = new GroundOverlay();
        myGroundOverlay.setPosition(overlayCenterPoint);
        Drawable d = ResourcesCompat.getDrawable(getResources(), R.mipmap.ic_imageonmap_test2, null);

        myGroundOverlay.setImage(d.mutate());
        //myGroundOverlay.setImageBitmap(bitmap);
        myGroundOverlay.setDimensions(2000000.0f);
        myGroundOverlay.setTransparency(0.25f);
        myGroundOverlay.setBearing(0);
        mMapView.getOverlays().add(myGroundOverlay);

        mMapView.invalidate();
////// second method
Bitmap src = BitmapFactory.decodeFile("/sdcard/osmdroid/20190722033213_1440103389.jpg");
        Bitmap bitmap2 = src.copy(Bitmap.Config.ARGB_8888, true);



        GroundOverlay myGroundOverlay2 = new GroundOverlay();

        myGroundOverlay2.setPosition(overlayCenterPoint);
        //myGroundOverlay2.setImageBitmap(src);
        myGroundOverlay2.setImageBitmap(bitmap2);
        //myGroundOverlay2.setDimensions(2000.0f);
        //myGroundOverlay2.setTransparency(0.25f);
        myGroundOverlay2.setBearing(0);
        mMapView.getOverlays().add(myGroundOverlay2);
        mMapView.invalidate();

【问题讨论】:

    标签: android bitmap overlay osmdroid


    【解决方案1】:

    我假设您使用的是 OSMBonusPack GroundOverlay。 您在方法 1 中的代码似乎是正确的(即使维度看起来很大)。 在方法 2 中,缺少 setDimensions。

    您是否尝试过“原样”OSMBonusPack tutorial(相同的位置/尺寸,来自资源的相同位图)?

    另外,试试:“setBearing(0.0f);” (我对从 int 到 float 的隐式转换没有信心)

    【讨论】:

      猜你喜欢
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多