Add maxResolution flag

This commit is contained in:
Ron Reiter 2011-04-04 02:57:10 +03:00
parent e766188689
commit 307f9d1871
4 changed files with 50 additions and 3 deletions

View File

@ -78,6 +78,12 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
if (options.quality) { if (options.quality) {
quality = this.options.quality; quality = this.options.quality;
} }
var maxResolution = 0;
if (options.maxResolution) {
maxResolution = this.options.maxResolution;
}
var destinationType = Camera.DestinationType.DATA_URL; var destinationType = Camera.DestinationType.DATA_URL;
if (this.options.destinationType) { if (this.options.destinationType) {
destinationType = this.options.destinationType; destinationType = this.options.destinationType;
@ -86,7 +92,7 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
if (typeof this.options.sourceType === "number") { if (typeof this.options.sourceType === "number") {
sourceType = this.options.sourceType; 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() { PhoneGap.addConstructor(function() {

View File

@ -0,0 +1,7 @@
source.dir=C:\\Work\\phonegap-android\\framework\\src
gen.dir=C:\\Work\\phonegap-android\\framework\\gen
resource.dir=C:\\Work\\phonegap-android\\framework\\res
asset.dir=C:\\Work\\phonegap-android\\framework\\assets
external.libs.dir=C:\\Work\\phonegap-android\\framework\\lib
native.libs.dir=C:\\Work\\phonegap-android\\framework\\lib
out.dir=C:\\Work\\phonegap-android\\framework\\out

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project name="PhoneGap" default="help"> <project name="PhoneGap" default="jar">
<!-- LOAD VERSION --> <!-- LOAD VERSION -->
<loadfile property="version" srcFile="../VERSION"> <loadfile property="version" srcFile="../VERSION">
@ -167,7 +167,7 @@
"build-javascript" => "build-uncompressed-javascript". "build-javascript" => "build-uncompressed-javascript".
--> -->
<target name="jar" depends="build-javascript, compile"> <target name="jar" depends="build-javascript, compile">
<jar jarfile="phonegap.${version}.jar" basedir="bin/classes" excludes="com/phonegap/R.class,com/phonegap/R$*.class"/> <jar jarfile="phonegap.${version}.jar" basedir="out/classes" excludes="com/phonegap/R.class,com/phonegap/R$*.class"/>
</target> </target>
<target name="phonegap_debug" depends="build-javascript, debug"> <target name="phonegap_debug" depends="build-javascript, debug">

View File

@ -44,6 +44,7 @@ public class CameraLauncher extends Plugin {
private static final int SAVEDPHOTOALBUM = 2; // Choose image from picture library (same as PHOTOLIBRARY for Android) 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 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 private Uri imageUri; // Uri of captured image
public String callbackId; public String callbackId;
@ -65,6 +66,7 @@ public class CameraLauncher extends Plugin {
PluginResult.Status status = PluginResult.Status.OK; PluginResult.Status status = PluginResult.Status.OK;
String result = ""; String result = "";
this.callbackId = callbackId; this.callbackId = callbackId;
this.mMaxResolution = 0;
try { try {
if (action.equals("takePicture")) { if (action.equals("takePicture")) {
@ -76,6 +78,9 @@ public class CameraLauncher extends Plugin {
if (args.length() > 2) { if (args.length() > 2) {
srcType = args.getInt(2); srcType = args.getInt(2);
} }
if (args.length() > 3) {
this.mMaxResolution = args.getInt(3);
}
if (srcType == CAMERA) { if (srcType == CAMERA) {
this.takePicture(args.getInt(0), destType); this.takePicture(args.getInt(0), destType);
} }
@ -145,6 +150,32 @@ public class CameraLauncher extends Plugin {
new String("Get Picture")), (srcType+1)*16 + returnType + 1); 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. * Called when the camera view exits.
* *
@ -168,6 +199,8 @@ public class CameraLauncher extends Plugin {
// Read in bitmap of captured image // Read in bitmap of captured image
Bitmap bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri); Bitmap bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri);
bitmap = scaleBitmap(bitmap);
// If sending base64 image back // If sending base64 image back
if (destType == DATA_URL) { if (destType == DATA_URL) {
this.processPicture(bitmap); this.processPicture(bitmap);
@ -230,6 +263,7 @@ public class CameraLauncher extends Plugin {
if (destType == DATA_URL) { if (destType == DATA_URL) {
try { try {
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
bitmap = scaleBitmap(bitmap);
this.processPicture(bitmap); this.processPicture(bitmap);
bitmap.recycle(); bitmap.recycle();
bitmap = null; bitmap = null;