我正在尝试将位图添加到谷歌地图标记图标。
以下是我将代码添加到标记图标的代码。由于位图大小
,应用程序崩溃错误: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;
}
答案 0 :(得分:-1)