Take Picture with Camera then Crop - android

I want to be able to take a picture with the the camera. I do it this way and it works:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, CAMERA_REQUEST);
After this is successful, I want user to be able to IMMEDIATELY view image and be able to crop.
I can do that like this:
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(Uri.fromFile(new File(file.toString())), "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, CAMERA_REQUEST);
How do I merge these two tasks so they happen one after the other? Do I have to have TWO startActivityForResult? Should it be merged? Or should the croppin ginfo be inside the normal?
getActivity();
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
// Cropping code here? another intent?
iPP.setImageBitmap(BitmapFactory.decodeFile(file.toString()));
imagePath = file.toString();
scaleImage();
new UploadImage().execute();
}

Create a new constant called CAMERA_CROP.
When you start the activity after taking a photo, send the CAMERA_CROP request code.
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
...
startActivityForResult(cropIntent, CAMERA_CROP);
}
When you return from the Crop Activity, handle the request code.
if (requestCode == CAMERA_CROP && resultCode == Activity.RESULT_OK) {
...
}

Related

image not cropping after cropped

I am attempting to crop an image using intent after the image is selected from the gallery. Here is my snippet of code
private void showFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
//******code for crop image
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
intent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
Here I am calling the above snippet with PICK_IMAGE_REQUEST intent handle
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
try {
Uri filePath = data.getData();
what could be wrong since I am using the same intent after cropping which is PICK_IMAGE_REQUEST
There are no documented and supported "crop" extras for ACTION_GET_CONTENT or any other standard Android Intent. Nor is there a documented and supported standard Intent action for cropping. There is no requirement for any device to have apps that support undocumented and unsupported extras, actions, etc.
If you want to crop an image, use any one of a number of existing open source libraries for image cropping.

marshmallow : java.lang.illegalargumentexception: mediaFileUri must be a File Uri

I am having problem in marshmallow device while cropping a photo after capturing it through camera.
It is working fine on below 6 version devices.
here is my code:
if (requestCode == CAMERA_PICTURE) {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// set data type to be sent , indicate image type and Uri of image
cropIntent.setDataAndType(mCapturedImageURI, "image/*");
List<ResolveInfo> list = getPackageManager().queryIntentActivities( cropIntent, 0 );
int size = list.size();
// handle the case if there's no cropper in the phone
if (size == 0) {
Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();
return;
} else {
//set crop properties
cropIntent.putExtra("crop", "true");
//indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
//indicate output X and Y
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
String fileName = Ut.getDateTimeStamp();
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
mCropImageURI = getContentResolver()
.insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT,
mCropImageURI);
//retrieve data on return
cropIntent.putExtra("return-data", true);
//start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, CROP_PICTURE);
return;
}
} else if (requestCode == CROP_PICTURE) {
getCameraPhotoFromIntent(data);
setImagePathToSource();
}
I have fixed by myself by removing
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT,
mCropImageURI);
as nexus 9 use Photos instead of gallery and "Photo" app not allowed Media URI .
So by removing this, I am able to crop the image.
Thank you.
Try this:
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.MARSHMALLOW) {
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCropImageURI);
}

Google Photos vs Stock Gallery - Intent Picker

In my app, I allow the user to pick a profile image from their gallery, like so:
When You click the first option, on my Android 5.0 device, I get this:
If I use the normal Gallery app that is based off the AOSP project, everything works fine and dandy. However, the Photo's app appears to use a different intent.
Here is how I handle code for the normal gallery:
Intent photoPickerIntent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
photoPickerIntent.putExtra("crop", "true");
photoPickerIntent.putExtra("outputX", 300);
photoPickerIntent.putExtra("outputY", 300);
photoPickerIntent.putExtra("aspectX", 1);
photoPickerIntent.putExtra("aspectY", 1);
photoPickerIntent.putExtra("scale", true);
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
photoPickerIntent.putExtra("outputFormat",
Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(photoPickerIntent, RESULT_LOAD_IMAGE);
And then the intent result handler:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RESULT_LOAD_IMAGE
&& resultCode == Activity.RESULT_OK) {
if (data != null) {
tempFile = getTempFile();
filePath = Environment.getExternalStorageDirectory() + "/"
+ "temporary_holder.jpg";
Log.d("LOAD REQUEST filePath", filePath);
Bitmap selectedImage = BitmapFactory.decodeFile(filePath);
iPP.setImageBitmap(selectedImage);
}
imagePath = filePath;
new UploadImage().execute();
}
}
Some of the helper functions from above:
private static Uri getTempUri() {
return Uri.fromFile(getTempFile());
}
private static File getTempFile() {
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
File file = new File(Environment.getExternalStorageDirectory(),
"temporary_holder.jpg");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
return null;
}
Some of that is probably not needed to show but I included it all in case it is interfering.
When I use Google Photos to pick a photo, my ImageView is blank (instead of filling with selected pick). The image is not selected and I can't go to the manual cropping view like I have it set with the Gallery. So basically, nothing happens.
NEW CODE IN RESPONSE TO ANSWER
photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
photoPickerIntent.putExtra("crop", "true");
photoPickerIntent.putExtra("outputX", 300);
photoPickerIntent.putExtra("outputY", 300);
photoPickerIntent.putExtra("aspectX", 1);
photoPickerIntent.putExtra("aspectY", 1);
photoPickerIntent.putExtra("scale", true);
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
photoPickerIntent.putExtra("outputFormat",
Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(photoPickerIntent, RESULT_LOAD_IMAGE);
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (data != null) {
Log.i("data", data.toString());
switch (requestCode) {
case RESULT_LOAD_IMAGE:
Log.i("RESULT_LOAD_IMAGE", "MARK");
// Received an image from the picker, now send an Intent for cropping
final String CROP_ACTION = "com.android.camera.action.CROP";
Intent photoCropIntent = new Intent(CROP_ACTION);
photoCropIntent.putExtra("crop", "true");
photoCropIntent.putExtra("aspectX", 1);
photoCropIntent.putExtra("aspectY", 1);
photoCropIntent.putExtra("outputX", 300);
photoCropIntent.putExtra("outputY", 300);
photoCropIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
photoCropIntent.putExtra("outputFormat",
Bitmap.CompressFormat.JPEG.toString());
photoCropIntent.setData(data.getData());
startActivityForResult(photoPickerIntent, RESULT_CROP_IMAGE);
break;
case RESULT_CROP_IMAGE:
Log.i("RESULT_CROP_IMAGE", "MARK");
tempFile = getTempFile();
imagePath = Environment.getExternalStorageDirectory() + "/" + "temporary_holder.jpg";
Log.i("imagePath", imagePath);
Uri selectedImageURI = data.getData();
InputStream image_stream;
try {
image_stream = getActivity().getContentResolver().openInputStream(selectedImageURI);
Bitmap bitmap = BitmapFactory.decodeStream(image_stream);
iPP.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
new UploadImage().execute();
break;
default:
// Handle default case
}
}
}
}
The above code isn't working either. I tried to make it resemble the answer below. What happens is:
I click "Choose from Gallery". And it does not give me a choice anymore, now it opens directly from the stock Gallery (that is not a big deal). I click on the image, and it ... appears to start the same intent over again -- it brings back the gallery wanting me to pick another image: instead of the Cropping Activity. Then after the second time, it will set my ImageView with the selected file.
Solution
First, update the photoPickerIntent to use ACTION_GET_CONTENT, and remove the extras related to cropping, since cropping will be handled by another Intent later:
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
// Do not include the extras related to cropping here;
// this Intent is for selecting the image only.
startActivityForResult(photoPickerIntent, RESULT_LOAD_IMAGE);
Then, onActivityResult() will have to handle two results: RESULT_LOAD_IMAGE will send another intent for the crop, and RESULT_CROP_IMAGE will continue processing as you did before:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (data != null) {
switch (requestCode) {
case RESULT_LOAD_IMAGE:
// Received an image from the picker, now send an Intent for cropping
final String CROP_ACTION = "com.android.camera.action.CROP";
Intent photoCropIntent = new Intent(CROP_ACTION);
photoCropIntent.setData(data.getData());
// TODO: first get this running without extras, then test each one here
startActivityForResult(photoCropIntent, RESULT_CROP_IMAGE);
break;
case RESULT_CROP_IMAGE:
// Received the cropped image, continue processing. Note that this
// is just copied and pasted from your question and may have
// omissions.
tempFile = getTempFile();
filePath = Environment.getExternalStorageDirectory() + "/"
+ "temporary_holder.jpg";
Log.d("LOAD REQUEST filePath", filePath);
Bitmap selectedImage = BitmapFactory.decodeFile(filePath);
iPP.setImageBitmap(selectedImage);
imagePath = filePath;
new UploadImage().execute();
break;
default:
// Handle default case
}
}
}
Note that although I've tested parts of this code, I haven't tested this entire block of code at runtime. If it doesn't work right out-of-the-box, though, it should be pretty close. Please comment if you have any questions or issues, and I'll update my answer accordingly.
Background
On an Android 5.0.1 (API 21) device with both AOSP Gallery2 (com.android.gallery3d) and Photos installed, I ran your Intent. I was prompted to choose between Gallery or Photos.
When I chose Photos, a picker was presented, and I picked an image. I was immediately returned to my Activity, with no cropping options.
When I chose Gallery, a picker was presented, and I picked an image. I was then prompted to choose an app for cropping. Both Photos and Gallery were presented as options for cropping.
Here's the interesting log output when choosing Gallery:
// Send the Intent
3-07 15:20:10.347 719-817/? I/ActivityManager﹕ Displayed android/com.android.internal.app.ResolverActivity: +127ms
// Choose Gallery
03-07 15:20:27.762 719-735/? I/ActivityManager﹕ START u0 {act=android.intent.action.PICK typ=image/* flg=0x3000000 cmp=com.android.gallery3d/.app.GalleryActivity (has extras)} from uid 10084 on display 0
// (fixing highlighting after MIME type on previous line) */
03-07 15:20:27.814 22967-22967/? W/GalleryActivity﹕ action PICK is not supported
03-07 15:20:27.814 22967-22967/? V/StateManager﹕ startState class com.android.gallery3d.app.AlbumSetPage
03-07 15:20:27.967 719-817/? I/ActivityManager﹕ Displayed com.android.gallery3d/.app.GalleryActivity: +190ms
// Pick an image
3-07 15:21:45.993 22967-22967/? V/StateManager﹕ startStateForResult class com.android.gallery3d.app.AlbumPage, 1
03-07 15:21:46.011 22967-22967/? D/AlbumPage﹕ onSyncDone: ********* result=0
03-07 15:21:46.034 22967-24132/? I/GLRootView﹕ layout content pane 1080x1701 (compensation 0)
03-07 15:21:48.447 719-1609/? I/ActivityManager﹕ START u0 {act=com.android.camera.action.CROP dat=content://media/external/images/media/1000 flg=0x2000000 cmp=android/com.android.internal.app.ResolverActivity (has extras)} from uid 10100 on display 0
First, note W/GalleryActivity﹕ action PICK is not supported. I'm not sure why it works, but according to Dianne Hackborn, "...you should consider ACTION_PICK deprecated. The modern action is ACTION_GET_CONTENT which is much better supported..." I've addressed this in my solution above.
The good news is, however, it seems that after picking an image, .putExtra("crop", "true"); causes Gallery to send another Intent for cropping. And the log clearly shows the action and data to use.
I tested this cropping intent, and I was prompted to choose an app for cropping, just like before. And again, both Photos and Gallery were presented as options, and they both brought up cropping interfaces.
It seems that although Photos supports cropping by Intent, it just ignores the extras relating to cropping in ACTION_PICK, whereas Gallery responds by sending another Intent after picking an image. Regardless, having the details of a working cropping Intent leads to the solution above.
I have solved this problem this way.
Pick image:
private void pickUserImage() {
if (doHavePermission()) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
photoPickerIntent.putExtra("crop", "true");
photoPickerIntent.putExtra("scale", true);
photoPickerIntent.putExtra("outputX", 256);
photoPickerIntent.putExtra("outputY", 256);
photoPickerIntent.putExtra("aspectX", 1);
photoPickerIntent.putExtra("aspectY", 1);
photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
startActivityForResult(photoPickerIntent, PICK_FROM_GALLERY);
}
}
used method getTempUri() is
private Uri getTempUri() {
return Uri.fromFile(getTempFile());
}
private File getTempFile() {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File file = new File(Environment.getExternalStorageDirectory(),TEMP_PHOTO_FILE);
try {
file.createNewFile();
} catch (IOException e) {
Log.printStackTrace(e);
}
return file;
} else {
return null;
}
}
get the picked image
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == PICK_FROM_GALLERY) {
if (data!=null) {
Uri selectedImageUri = data.getData();
//String tempPath = getPath(selectedImageUri, UserProfileActivity.this);
String url = data.getData().toString();
if (url.startsWith("content://com.google.android.apps.photos.content")){
try {
InputStream is = getContentResolver().openInputStream(selectedImageUri);
if (is != null) {
Bitmap selectedImage = BitmapFactory.decodeStream(is);
//You can use this bitmap according to your purpose or Set bitmap to imageview
if (selectedImage != null) {
isImageUpdated = true;
isImageUpdated = true;
Bitmap resizedBitmap = null;
if (selectedImage.getWidth() >= 256 && selectedImage.getHeight() >= 256) {
resizedBitmap = Bitmap.createBitmap(selectedImage,
selectedImage.getWidth() - 128,
selectedImage.getHeight() - 128,
256, 256);
}
if (resizedBitmap != null) {
imageViewUserImage.setImageDrawable(ImageHelper.getRoundedCornerImage(resizedBitmap, 20));
} else {
imageViewUserImage.setImageDrawable(ImageHelper.getRoundedCornerImage(selectedImage, 20));
}
}
}
} catch (FileNotFoundException e) {
Log.printStackTrace(e);
}
} else {
File tempFile = getTempFile();
String filePath = Environment.getExternalStorageDirectory() + "/" + TEMP_PHOTO_FILE;
Log.d(TAG, "path " + filePath);
Bitmap selectedImage = BitmapFactory.decodeFile(filePath);
if (selectedImage != null) {
isImageUpdated = true;
imageViewUserImage.setImageDrawable(ImageHelper.getRoundedCornerImage(selectedImage, 20));
}
if (tempFile.exists()) {
tempFile.delete();
}
}
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
Image converted to rounded corner image as follows:
public class ImageHelper {
public static RoundedBitmapDrawable getRoundedCornerImage(Bitmap bitmap, int cornerRadius) {
RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(null, bitmap);
dr.setCornerRadius(cornerRadius);
return dr;
}
}
Its too late to answer but it can help someone else.

Losing a lot of quality on image crop

I'm capturing an image from camera and then saving it do sqlite database.
After that I allow user to crop it. After the whole process quality is very very poor.
I'm testing it on Nexus7 and I know it's front camera is poor but right after crop app opens, the picture is very small. It takes like 1/5 of s creen in the crop activity and I don't know why.
This what happens onActivityResult (capturing taken picture)
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
String path = Images.Media.insertImage(getActivity().getContentResolver(), bitmap, "Title", null);
Uri imageUri = Uri.parse(path);
if (!doCrop(imageUri)) saveNewAvatar(bitmap);
}
}
And here is doCrop(Uri uri) method:
private void doCrop(final Uri imageUri) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
List<ResolveInfo> list = getActivity().getPackageManager().queryIntentActivities( intent, 0 );
int size = list.size();
intent.setData(imageUri);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
if (size == 1) {
Intent i = new Intent(intent);
ResolveInfo res = list.get(0);
i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
startActivityForResult(i, CROP);
}
}
After the whole process picture is very very small.
EDIT:
Did some research and followed code from this thread
Ended up with this:
There are many wrong (as in: maybe works, but that's not the way you do such things on Android) things about your code, but the source of the problem is that you read the image from the data key in extras. The version in extras is just a miniature, and it is of very low quality.
What you need to do is change the way you invoke the camera. This is slightly counter-intuitive, but you do not get the url to the picture taken from the camera, but just the opposite: pass an url to the camera and it will try and put the picture there.
The url might point to the SD card or to you own ContentProvider.

Intent setDataAndType as bitmap

I'm trying to use a method to crop a image. Exactly this method:
private void performCrop() {
try {
//call the standard crop action intent (the user device may not support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
//indicate image type and Uri
cropIntent.setDataAndType(**HERE**, "image/*");
//set crop properties
cropIntent.putExtra("crop", "true");
//indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
//indicate output X and Y
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
//retrieve data on return
cropIntent.putExtra("return-data", true);
//start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, 1234);
}
catch(ActivityNotFoundException anfe){
Log.d("debugging","EXCEPTION");/*
//display an error message
String errorMessage = "Whoops - your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();*/
}
}
This line, asks for a Uri Data and String Type.
cropIntent.setDataAndType(**HERE**, "image/*");
But I just want to put this bitmap
Bitmap fotoCreada;
as Data, but I don't know how to do it.
Is there any way to achieve this?
Thanks.
EDIT
Okay, this is my code right now:
There's a button. When you click it:
public void onClick(View v) {
Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
if(isSDPresent) {
//Creem carpeta
File folder = new File(Environment.getExternalStorageDirectory().toString()+"/pic/");
folder.mkdirs();
//Recuperem data actual
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String currentDateandTime = sdf.format(new Date());
//Cridem a la camara.
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
resultingFile=new File(folder.toString() + "/"+currentDateandTime+".jpg");
Uri uriSavedImage=Uri.fromFile(resultingFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
//Començem activity
startActivityForResult(cameraIntent, 1888);
} else {
Toast toast = Toast.makeText(getActivity(), "Issues while accessing sdcard.", Toast.LENGTH_SHORT);
toast.show();
}
}
As you can see, it's calling startActivityForResult. Basically takes a picture, and I retrieve it on activityResult:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("debugging",""+resultCode);
if( requestCode == 1888 && resultCode == -1) { //-1 = TOT HA ANAT BE.
Bitmap photo = BitmapFactory.decodeFile(resultingFile.getPath());
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap photoRotated = Bitmap.createBitmap(photo, 0, 0, photo.getWidth(), photo.getHeight(), matrix, true);
this.fotoCreada=photoRotated;
((ImageView) myFragmentView.findViewById(R.id.fotoCapturada)).setImageBitmap(this.fotoCreada);
try {
FileOutputStream out = new FileOutputStream(this.resultingFile.getPath());
this.fotoCreada.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
performCrop();
}
if (requestCode == 1234 && resultCode == -1){
Bitmap bitmap = (Bitmap) data.getParcelableExtra("BitmapImage");
Log.d("debugging",""+bitmap.getHeight());
}
}
And as you can see from previous code, as I retrieve the bitmap, I call method performCrop. It's code, now, is:
private void performCrop() {
try {
//call the standard crop action intent (the user device may not support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
//indicate image type and Uri
//cropIntent.setDataAndType(this.picUri, "image/*");
cropIntent.putExtra("BitmapImage", this.fotoCreada);
//set crop properties
cropIntent.putExtra("crop", "true");
//indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
//indicate output X and Y
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
//retrieve data on return
cropIntent.putExtra("return-data", true);
//start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, 1234);
Log.d("debugging","he acabat performCrop");
}
catch(ActivityNotFoundException anfe){
Log.d("debugging","EXCEPTION");
//display an error message
String errorMessage = "Whoops - your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
But startActivityForResult from performCrop never ends up calling onActivityResult. Log cat says it just entered once, and should enter Twice. First one from the camera Activity and second from Crop activity.
-1
he acabat performCrop
Hope it's clear enough.
Thanks.
Bitmap implements Parcelable, so you could always pass it in the intent:
Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImage", bitmap);
and retrieve it on the other end:
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
However, if the bitmap exists as a file or a resource, its is always better to pass the URI or ResourceID of the bitmap and not the bitmap itself. Passing the entire bitmap requires a lot of memory. Passing the URL requires very little memory and allows each activity to load and scale the bitmap as they need it.
Use Intent.putExtra. A bitmap is a parceable, so it will work. setDataAndType is used for URIs, but you aren't referencing a resource on the web or on disk.

Categories

Resources