Bitmap

I am trying to capture a photo and then crop it. So basically, I fire up the intent camera and then start recycling.

Since I cannot pass a large bitmap through the "onActivityResult" data, I created a URI to save the image directly to the SDCard, but for some reason it is saved on the emulator but not on the real device. (I mean, CROP is not saved on the real device.)

This is the code:

File resultingFile;
Bitmap fotoCreada;
Uri uriFoto;

      

Camera purpose:

File folder = new File(Environment.getExternalStorageDirectory().toString()+"/PictureFolder/");
folder.mkdirs();
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
resultingFile=new File(folder.toString() + "/"+currentDateandTime+".jpg");
this.uriFoto=Uri.fromFile(resultingFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, this.uriFoto);
startActivityForResult(cameraIntent, 1888); 

      

Then I get the result:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    //Si venim de la camera
    if( requestCode == 1888 && resultCode == -1) { //-1 = TOT HA ANAT BE.
        Bitmap photo = BitmapFactory.decodeFile(resultingFile.getPath());
        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        matrix.postScale(0.5f,0.5f);
        Bitmap photoRotated = Bitmap.createBitmap(photo, 0, 0, photo.getWidth(), photo.getHeight(), matrix, true);
        //Desem foto rotada.
        this.fotoCreada=photoRotated;
        try {
            FileOutputStream out = new FileOutputStream(this.resultingFile.getPath());
            this.fotoCreada.compress(Bitmap.CompressFormat.PNG, 90, out);
        } catch (Exception e) {
            e.printStackTrace();
        }
        performCrop();
    }

      

So, I call performCrop ();

private void performCrop() {
    try {
        Log.d("debugging","Estic a crop. La foto Ês:"+this.uriFoto);
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        cropIntent.setDataAndType(this.uriFoto, "image/*");
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
        cropIntent.putExtra("outputX", 600);
        cropIntent.putExtra("outputY", 600);
        //cropIntent.putExtra("return-data", true);
        cropIntent.putExtra("ouput", this.uriFoto);
        startActivityForResult(cropIntent,1234);
    }
    catch(ActivityNotFoundException anfe){
        //display an error message
        String errorMessage = "Whoops - your device doesn't support the crop action!";
        Toast toast = Toast.makeText(this.cont, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }
}

      

As you can see:

cropIntent.putExtra("ouput", this.uriFoto);

      

It basically says to output the trim to that URI. The URI is correct as I debugged it (LogCat):

Estimate the harvest. La foto Ês: file: ///mnt/sdcard/PictureFolder/20130123_223058.jpg

And so, I will return to the activity result:

[... previous onactivityresult]
if (requestCode == 1234 && resultCode == -1){
        Log.d("debugging","Ha acabat el croop.");
        Uri imageUri = this.uriFoto;
        try {
            Bitmap photo = MediaStore.Images.Media.getBitmap(this.cont.getContentResolver(), imageUri);
            this.fotoCreada=photo;
            ((ImageView) myFragmentView.findViewById(R.id.fotoCapturada)).setImageBitmap(this.fotoCreada);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //Bitmap photo = BitmapFactory.decodeFile(resultingFile.getPath());     
    }

      

But I end up showing (setImageBitmap (this.fotoCreada);) the captured image from the camera, but not the cropped image. This happens on a real device, but not on an emulator!

I tried to explain in the best way. Feel free to ask.

Thank.

+3


source to share





All Articles