diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2017-10-29 08:01:10 -0700 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2017-11-01 14:56:37 -0700 |
commit | a5ff277ed98dfc7a21ef92f99567ee5a682a2210 (patch) | |
tree | c684889d4001910114a94bbc6d30a9c0b91843db /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnaphotUtil.java | |
parent | cb7f6dfaec2f90a81d588c2458e01d2a191f9ba1 (diff) | |
download | qtlocation-mapboxgl-a5ff277ed98dfc7a21ef92f99567ee5a682a2210.tar.gz |
[android] - add logo resize to MapSnapshotter
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnaphotUtil.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnaphotUtil.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnaphotUtil.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnaphotUtil.java new file mode 100644 index 0000000000..da86dc51fb --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnaphotUtil.java @@ -0,0 +1,29 @@ +package com.mapbox.mapboxsdk.snapshotter; + +import android.graphics.BitmapFactory; + +class MapSnaphotUtil { + + 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) { + + final int halfHeight = height / 2; + final int halfWidth = width / 2; + + // Calculate the largest inSampleSize value that is a power of 2 and keeps both + // height and width larger than the requested height and width. + while ((halfHeight / inSampleSize) >= reqHeight + && (halfWidth / inSampleSize) >= reqWidth) { + inSampleSize *= 2; + } + } + return inSampleSize; + } + + +} |