mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 23:42:53 +08:00
Switch getPicture from Gallery to use file instead of content resolver
This commit is contained in:
parent
8aa9d8213d
commit
483e5dfbea
@ -428,7 +428,6 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
|
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
Uri uri = intent.getData();
|
Uri uri = intent.getData();
|
||||||
android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver();
|
|
||||||
|
|
||||||
// If you ask for video or all media type you will automatically get back a file URI
|
// If you ask for video or all media type you will automatically get back a file URI
|
||||||
// and there will be no attempt to resize any returned data
|
// and there will be no attempt to resize any returned data
|
||||||
@ -437,32 +436,30 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If sending base64 image back
|
// If sending base64 image back
|
||||||
|
|
||||||
|
// Get the path to the image. Makes loading so much easier.
|
||||||
|
String imagePath = FileUtils.getRealPathFromURI(uri, this.cordova);
|
||||||
if (destType == DATA_URL) {
|
if (destType == DATA_URL) {
|
||||||
try {
|
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
|
||||||
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
String[] cols = { MediaStore.Images.Media.ORIENTATION };
|
||||||
String[] cols = { MediaStore.Images.Media.ORIENTATION };
|
Cursor cursor = this.cordova.getActivity().getContentResolver().query(intent.getData(),
|
||||||
Cursor cursor = this.cordova.getActivity().getContentResolver().query(intent.getData(),
|
cols,
|
||||||
cols,
|
null, null, null);
|
||||||
null, null, null);
|
if (cursor != null) {
|
||||||
if (cursor != null) {
|
cursor.moveToPosition(0);
|
||||||
cursor.moveToPosition(0);
|
rotate = cursor.getInt(0);
|
||||||
rotate = cursor.getInt(0);
|
cursor.close();
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
if (rotate != 0) {
|
|
||||||
Matrix matrix = new Matrix();
|
|
||||||
matrix.setRotate(rotate);
|
|
||||||
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
|
||||||
}
|
|
||||||
bitmap = scaleBitmap(bitmap);
|
|
||||||
this.processPicture(bitmap);
|
|
||||||
bitmap.recycle();
|
|
||||||
bitmap = null;
|
|
||||||
System.gc();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
this.failPicture("Error retrieving image.");
|
|
||||||
}
|
}
|
||||||
|
if (rotate != 0) {
|
||||||
|
Matrix matrix = new Matrix();
|
||||||
|
matrix.setRotate(rotate);
|
||||||
|
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
||||||
|
}
|
||||||
|
bitmap = scaleBitmap(bitmap);
|
||||||
|
this.processPicture(bitmap);
|
||||||
|
bitmap.recycle();
|
||||||
|
bitmap = null;
|
||||||
|
System.gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If sending filename back
|
// If sending filename back
|
||||||
@ -470,7 +467,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
// Do we need to scale the returned file
|
// Do we need to scale the returned file
|
||||||
if (this.targetHeight > 0 && this.targetWidth > 0) {
|
if (this.targetHeight > 0 && this.targetWidth > 0) {
|
||||||
try {
|
try {
|
||||||
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
|
||||||
bitmap = scaleBitmap(bitmap);
|
bitmap = scaleBitmap(bitmap);
|
||||||
|
|
||||||
String fileName = DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg";
|
String fileName = DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg";
|
||||||
|
Loading…
Reference in New Issue
Block a user