vendredi 27 mars 2015

Remove the cropping from intent ACTION_IMAGE_CAPTURE android

I am capturing the image from the following below code and it also perform the cropping the image it works fine but i want to remove the cropping functionality from that, i tried to do that by commenting the cropping but it crashed in some devices please can any one give the the right code to remove cropping from that code that will work fine in all the android devices



public class NewPhotoFragment extends Fragment implements OnClickListener{


/**********DECLARES*************/
private ImageView imgVPicPhoto;
private Uri fileUri; // file url to store image
private int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100;
private int PIC_CROP = 200;
private String filePath;
private FunctionHelper functionHelper;
private CreateComplaint createComplaint;

@Override
public void onViewCreated(View rootView, Bundle savedInstanceState) {
super.onViewCreated(rootView, savedInstanceState);
imgVPicPhoto = (ImageView) rootView.findViewById(R.id.imgVPicPhoto);

imgVPicPhoto.setOnClickListener(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater
.inflate(R.layout.frag_compalint_photo, container, false);
}

@Override
public void onStart() {
// TODO Auto-generated method stub
super.onStart();
functionHelper=new FunctionHelper(getActivity());
createComplaint=((MyAccessibility)getActivity()).getCreateComplaint();
if (createComplaint.getPhotoBitmap() != null)
imgVPicPhoto.setImageBitmap(createComplaint.getPhotoBitmap());
}
private void captureImagenew() {

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try {

String currentTimeMillis = String.valueOf(System
.currentTimeMillis());
String subString = currentTimeMillis.substring(10,
currentTimeMillis.length());
File imageDirectory = new File(
Environment.getExternalStorageDirectory()
+ "/DCIM/"
+ getActivity().getResources().getString(
R.string.folder_name));

if (!imageDirectory.exists()) {
imageDirectory.mkdir();
}
// Do something on success
File imageFileName = new File(imageDirectory, "test" + "_"
+ subString + ".jpg");

fileUri = Uri.fromFile(imageFileName);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, fileUri);
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
intent.putExtra("android.intent.extras.CAMERA_FACING", 1);
filePath = fileUri.getPath();
createComplaint.setFilepathImage(filePath);
System.out.println("filepath---->>>>> " + filePath);
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
} catch (Exception e) {
e.printStackTrace();
functionHelper.showToast("File not captured");
}


}


private void performCrop() {

Intent cropIntent = new Intent("com.android.camera.action.CROP");

// indicate image type and Uri
cropIntent.setDataAndType(fileUri, "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);
cropIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, fileUri);

// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100) {
if (resultCode == -1) {
// successfully captured the image
// display it in image view

performCrop();

}else if (resultCode == 0) {
// user cancelled Image capture
functionHelper.showToast("User cancelled image capture");
} else {
functionHelper.showToast("Sorry! Failed to capture image");
}
}else if(requestCode == PIC_CROP){
if(data!=null){
Bundle extras = data.getExtras();
fileUri = data.getData();

Bitmap bmp = (Bitmap) extras.get("data");
OutputStream stream;
try {
stream = new FileOutputStream(filePath);
bmp.compress(CompressFormat.JPEG, 100, stream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
createComplaint.setPhotoBitmap(bmp);
imgVPicPhoto.setImageBitmap(bmp);
}else
functionHelper.showToast("Nothing is selected");
}
}


@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.imgVPicPhoto:
captureImagenew();
break;
default:
break;
}
}


}


Aucun commentaire:

Enregistrer un commentaire