aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorMarco Jacob <mjacob@union06.de>2013-05-23 08:33:55 -0700
committerMarco Jacob <mjacob@union06.de>2013-05-23 08:33:55 -0700
commitf824def217f651d6400aea9c0cd4b25f76b3c40d (patch)
treedf109348b4cccf1c424cf15d1fd6743a74000b86 /main/src
parente734590a5aadc1881d9dec012a2a11704fe012aa (diff)
parent45a84e834ce21317d84f2daed21ed5ad7af91467 (diff)
downloadcgeo-f824def217f651d6400aea9c0cd4b25f76b3c40d.zip
cgeo-f824def217f651d6400aea9c0cd4b25f76b3c40d.tar.gz
cgeo-f824def217f651d6400aea9c0cd4b25f76b3c40d.tar.bz2
Merge pull request #2768 from marco-jacob/issue#2736
fixes #2736 - avoid OOM on upload log image
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/ImageSelectActivity.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/ImageSelectActivity.java b/main/src/cgeo/geocaching/ImageSelectActivity.java
index 4abf310..2a87691 100644
--- a/main/src/cgeo/geocaching/ImageSelectActivity.java
+++ b/main/src/cgeo/geocaching/ImageSelectActivity.java
@@ -261,15 +261,27 @@ public class ImageSelectActivity extends AbstractActivity {
* @return
*/
private String writeScaledImage(String filePath) {
- Bitmap image = BitmapFactory.decodeFile(filePath);
scaleChoiceIndex = scaleView.getSelectedItemPosition();
int maxXY = getResources().getIntArray(R.array.log_image_scale_values)[scaleChoiceIndex];
- String uploadFilename = filePath;
- if (maxXY > 0) {
- BitmapDrawable scaledImage = ImageHelper.scaleBitmapTo(image, maxXY, maxXY);
- uploadFilename = getOutputImageFile().getPath();
- ImageHelper.storeBitmap(scaledImage.getBitmap(), Bitmap.CompressFormat.JPEG, 75, uploadFilename);
+ if (maxXY == 0) {
+ return filePath;
}
+ BitmapFactory.Options sizeOnlyOptions = new BitmapFactory.Options();
+ sizeOnlyOptions.inJustDecodeBounds = true;
+ BitmapFactory.decodeFile(filePath, sizeOnlyOptions);
+ int myMaxXY = Math.max(sizeOnlyOptions.outHeight, sizeOnlyOptions.outWidth);
+ int sampleSize = myMaxXY / maxXY;
+ Bitmap image;
+ if (sampleSize > 1) {
+ BitmapFactory.Options sampleOptions = new BitmapFactory.Options();
+ sampleOptions.inSampleSize = sampleSize;
+ image = BitmapFactory.decodeFile(filePath, sampleOptions);
+ } else {
+ image = BitmapFactory.decodeFile(filePath);
+ }
+ BitmapDrawable scaledImage = ImageHelper.scaleBitmapTo(image, maxXY, maxXY);
+ String uploadFilename = getOutputImageFile().getPath();
+ ImageHelper.storeBitmap(scaledImage.getBitmap(), Bitmap.CompressFormat.JPEG, 75, uploadFilename);
return uploadFilename;
}