首页 > 解决方案 > 如何在osmdroid的mapview上将jpg文件叠加为位图文件

问题描述

我使用 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();

标签: androidbitmapoverlayosmdroid

解决方案


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

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

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


推荐阅读