I have implemented code for both image capturing and cropping functionality. Same is working in Lenovo A536 and Huwaii Honor Holly but not working in Huwaii Ascend P7-L10. Even all of them have android 4.4.2 with Loilipop update.
-
First issue is that caputred image is not getting stored on the sd card while I have already provided permission for write access.
-
Second is I am not able to implement crop view in square form. It is adjustable by the end user while selecting image from gallery in only the phone above mentioned. My code is :
public void selectGiniPicture(View view) { isGiniImageSelected = true; final CharSequence[] options = { "Take Picture", "Choose from Gallery","Cancel" }; AlertDialog.Builder builder = new AlertDialog.Builder(WorkerRegActivity.this); builder.setTitle("Select Your Picture!"); builder.setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals("Take Picture")) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 1); } else if (options[item].equals("Choose from Gallery")) { Intent intent = new Intent(); //Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.putExtra("crop", "true"); //intent.putExtra("aspectX", 0); //intent.putExtra("aspectY", 0); intent.putExtra("outputX", 225); intent.putExtra("outputY", 225); intent.putExtra("scale", true); intent.putExtra("scaleUpIfNeeded", true); intent.putExtra("return-data", true); startActivityForResult(Intent.createChooser(intent, "Complete action using"), 2); } else if (options[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show(); }
Perform Crop function for camera
private void performCrop() {
// take care of exceptions
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(picUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// indicate aspect of desired crop
//cropIntent.putExtra("aspectX", 0);
//cropIntent.putExtra("aspectY", 0);
// indicate output X and Y
cropIntent.putExtra("outputX", 225);
cropIntent.putExtra("outputY", 225);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, 6);
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
Toast toast = Toast
.makeText(this, "This device doesn't support the crop action!", Toast.LENGTH_SHORT);
toast.show();
}
}
OnActivityResult Function is as:
if (resultCode == RESULT_OK)
{
if (requestCode == 1)
{
picUri = data.getData();
performCrop();
}
else if (requestCode == 2) {
Bundle extras = data.getExtras();
if (extras != null) {
Bitmap photo = extras.getParcelable("data");
capturedImage.setImageBitmap(photo);
}
}
}
Aucun commentaire:
Enregistrer un commentaire