使用android将图像加载到地图标记中

时间:2016-01-09 12:55:38

标签: android google-maps google-maps-markers

我正在尝试将位图添加到谷歌地图标记图标。

以下是我将代码添加到标记图标的代码。由于位图大小

,应用程序崩溃

错误:java.lang.IllegalArgumentException:dimension4096x8192的纹理大于支持的最大大小4096x4096

BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        int imageHeight = options.outHeight;
        int imageWidth = options.outWidth;
        String imageType=options.outMimeType;
        if(imageWidth > imageHeight) {
            options.inSampleSize = calculateInSampleSize(options,10,10);//if landscape
        } else{
            options.inSampleSize = calculateInSampleSize(options,10,10);//if portrait
        }
        options.inJustDecodeBounds = false;


        Bitmap  mapbitmap = BitmapFactory.decodeFile("/storage/emulated/0/Pictures/TAG_IMG_25.2571724_55.2994563.jpg", options);

latLng=new LatLng(25.254376, 55.2973058);

marker = googleMap.addMarker(new MarkerOptions()
            .position(latLng)
            .title(_title)
            .snippet("dubai")
            .icon(BitmapDescriptorFactory.fromBitmap(mapbitmap)));

public static int calculateInSampleSize(
            BitmapFactory.Options options, int reqWidth, int reqHeight) {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

        if (height > reqHeight || width > reqWidth) {

            // Calculate ratios of height and width to requested height and width
            final int heightRatio = Math.round((float) height / (float) reqHeight);
            final int widthRatio = Math.round((float) width / (float) reqWidth);

            // Choose the smallest ratio as inSampleSize value, this will guarantee
            // a final image with both dimensions larger than or equal to the
            // requested height and width.
            inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
        }

        return inSampleSize;
    }

1 个答案:

答案 0 :(得分:-1)

答案就在你的问题中。

{{1}}

因此,您必须使用任何图像编辑器(如Photoshop)将图像尺寸缩小到4096x4096以下。

如果您不熟悉,请参阅tutorial