From 2b20b1880d99d0f4d805064847e8d73fb4b2db33 Mon Sep 17 00:00:00 2001 From: macdonst Date: Sun, 11 Sep 2011 03:49:00 +0800 Subject: [PATCH] Fix for issue #196: targetWidth/targetHeight ignored when PictureSourceType is library --- .../src/com/phonegap/CameraLauncher.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/framework/src/com/phonegap/CameraLauncher.java b/framework/src/com/phonegap/CameraLauncher.java index 58526653..b107e77b 100755 --- a/framework/src/com/phonegap/CameraLauncher.java +++ b/framework/src/com/phonegap/CameraLauncher.java @@ -10,6 +10,7 @@ package com.phonegap; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -75,6 +76,9 @@ public class CameraLauncher extends Plugin { try { if (action.equals("takePicture")) { int destType = DATA_URL; + this.targetHeight = 0; + this.targetWidth = 0; + if (args.length() > 1) { destType = args.getInt(1); } @@ -340,7 +344,30 @@ public class CameraLauncher extends Plugin { // If sending filename back else if (destType == FILE_URI) { - this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); + // Do we need to scale the returned file + if (this.targetHeight != 0 && this.targetWidth != 0) { + try { + Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); + bitmap = scaleBitmap(bitmap); + + String fileName = DirectoryManager.getTempDirectoryPath(ctx) + "/resize.jpg"; + OutputStream os = new FileOutputStream(fileName); + bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); + os.close(); + + bitmap.recycle(); + bitmap = null; + + this.success(new PluginResult(PluginResult.Status.OK, ("file://" + fileName)), this.callbackId); + System.gc(); + } catch (Exception e) { + e.printStackTrace(); + this.failPicture("Error retrieving image."); + } + } + else { + this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); + } } } else if (resultCode == Activity.RESULT_CANCELED) {