android - 如何在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();
解决方案
我假设您使用的是 OSMBonusPack GroundOverlay。您在方法 1 中的代码似乎是正确的(即使维度看起来很大)。在方法 2 中,缺少 setDimensions。
您是否“按原样”尝试了OSMBonusPack 教程(相同的位置/尺寸,来自资源的相同位图)?
另外,尝试:“setBearing(0.0f);” (我对从 int 到 float 的隐式转换没有信心)
推荐阅读
- c# - 查看距剖切面一定距离的剖面
- docker - 运行 npm install 时 Docker 没有这样的文件 package.json
- javascript - 页面加载之间的 javascript worker
- mysql - 如何将列名打印为mysql中的行数?
- c - 将我的 yacc 和 lex 文件放在一起时,yacc 无法识别我的令牌。为什么?
- mysql - 尝试解决 MYSQL 更新触发器的语法错误
- python - 如何在kivy中固定一条线的长度
- python - 如何将数组转换为结构化数组的特殊项并将其还原?
- javascript - 用户在Java中输入密码错误3次后如何让我的Java代码终止
- html - 如何使用 html 和 css 制作比例 4 列布局