diff --git a/framework/assets/js/camera.js b/framework/assets/js/camera.js index 1c4be96d..0238c978 100755 --- a/framework/assets/js/camera.js +++ b/framework/assets/js/camera.js @@ -78,6 +78,12 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options) if (options.quality) { quality = this.options.quality; } + + var maxResolution = 0; + if (options.maxResolution) { + maxResolution = this.options.maxResolution; + } + var destinationType = Camera.DestinationType.DATA_URL; if (this.options.destinationType) { destinationType = this.options.destinationType; @@ -86,7 +92,7 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options) if (typeof this.options.sourceType === "number") { sourceType = this.options.sourceType; } - PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType]); + PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, maxResolution]); }; PhoneGap.addConstructor(function() { diff --git a/framework/build.xml b/framework/build.xml index d48e8a1f..05da712a 100755 --- a/framework/build.xml +++ b/framework/build.xml @@ -1,5 +1,5 @@ - + diff --git a/framework/src/com/phonegap/CameraLauncher.java b/framework/src/com/phonegap/CameraLauncher.java index 1ad4bac0..3eb09092 100755 --- a/framework/src/com/phonegap/CameraLauncher.java +++ b/framework/src/com/phonegap/CameraLauncher.java @@ -45,6 +45,7 @@ public class CameraLauncher extends Plugin { private static final int SAVEDPHOTOALBUM = 2; // Choose image from picture library (same as PHOTOLIBRARY for Android) private int mQuality; // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) + private int mMaxResolution; // Maximum resolution of picture taken from camera (width or height, depending on the ratio) private Uri imageUri; // Uri of captured image public String callbackId; @@ -66,6 +67,7 @@ public class CameraLauncher extends Plugin { PluginResult.Status status = PluginResult.Status.OK; String result = ""; this.callbackId = callbackId; + this.mMaxResolution = 0; try { if (action.equals("takePicture")) { @@ -77,6 +79,9 @@ public class CameraLauncher extends Plugin { if (args.length() > 2) { srcType = args.getInt(2); } + if (args.length() > 3) { + this.mMaxResolution = args.getInt(3); + } if (srcType == CAMERA) { this.takePicture(args.getInt(0), destType); } @@ -146,6 +151,32 @@ public class CameraLauncher extends Plugin { new String("Get Picture")), (srcType+1)*16 + returnType + 1); } + /** + * Scales the bitmap according to the requested size. + * + * @param bitmap The bitmap to scale. + * @return Bitmap A new Bitmap object of the same bitmap after scaling. + */ + public Bitmap scaleBitmap(Bitmap bitmap) { + int newWidth = 0; + int newHeight = 0; + + if (this.mMaxResolution != 0) { + + // Check if a horizontal or vertical picture was taken + if (bitmap.getWidth() > bitmap.getHeight()) { + newWidth = this.mMaxResolution; + newHeight = (int)(((float)bitmap.getHeight() / (float)bitmap.getWidth()) * newWidth); + } else { + newHeight = this.mMaxResolution; + newWidth = (int)(((float)bitmap.getWidth() / (float)bitmap.getHeight()) * newHeight); + } + // Scale the bitmap before returning a compressed image + return Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true); + } + return bitmap; + } + /** * Called when the camera view exits. * @@ -175,6 +206,8 @@ public class CameraLauncher extends Plugin { bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } + bitmap = scaleBitmap(bitmap); + // If sending base64 image back if (destType == DATA_URL) { this.processPicture(bitmap); @@ -237,6 +270,7 @@ public class CameraLauncher extends Plugin { if (destType == DATA_URL) { try { Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); + bitmap = scaleBitmap(bitmap); this.processPicture(bitmap); bitmap.recycle(); bitmap = null;