【问题标题】:Failed to decode image. The provided image must be a Bitmap. I do provide a bitmap无法解码图像。提供的图像必须是位图。我确实提供了位图
【发布时间】:2017-12-02 11:04:34
【问题描述】:

目前,我正在开发一个应用程序,该应用程序使用 Google Maps API 在地图上绘制用户拍照的点。这些图像是从我创建的数据库中存储和检索的。当地图第一次启动时,我检索图片并绘制点。从数据库中获取 byte[] 后,我将其转换为位图,并将标记图标设置为 DescriptorFactory 中的位图。但是,编译器会抛出有关提供的图像必须是位图的错误。我有 99% 的把握。

private void plotMarkers(GoogleMap mMap) {

    ImageHelper imageHelper = new ImageHelper(this, null, null, 1);
    markers = imageHelper.selectAll();
    if(markers.size() > 0)
    {
        int index = 0;
        for (MyMarker myMarker : markers)
        {
            Bitmap bitmap = (imageHelper.getImage(index));
            MarkerOptions markerOption = new MarkerOptions()
                    .position(new LatLng(myMarker.getLatitude(), myMarker.getLongitude()))
                    .icon(BitmapDescriptorFactory.fromBitmap(bitmap));


            Marker currentMarker = mMap.addMarker(markerOption);

            markersHashMap.put(currentMarker, myMarker);
            index++;
        }
    }
}

【问题讨论】:

    标签: android google-maps bitmap


    【解决方案1】:

    尝试使用Bitmap.createBitmap(bitmap)

    另外请下次指定全局变量的类型。

    【讨论】:

    • 感谢您的回复,下次我一定会这样做的。事实证明,我有正确的方法调用,但我的索引从零开始,而实际上 SQLite 从 1 开始。这是一个学习过程!
    猜你喜欢
    • 2018-03-12
    • 2020-05-23
    • 2019-03-19
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多