Monday , November 29 2021

Crop Image Android Tutorial – Pick and Crop Image in Android – Android Coding by DMTechnolab

The package Pinch.Bitman.With.bestimagecropperever;

Import Android.Clearly;

Import Android.Annotation.Suppress;

Import Android.App.The activity;

Import Android.Content.Intent;

Import Android.Content.in the evening.package manager;

Import Android.The trap.to hate;

Import Android.The.Bundle;

Import Android.Support.v7.App.AppCompatActivity;

Import Android.Opinion.Opinion;

Import Android.Widget.ImageButton;

Import Android.Widget.ImageView;

Import Android.Widget.Toast;

Import With.Thetofdev.Edmodo.Crooked.crop image;

Import With.Thetofdev.Edmodo.Crooked.CropImageView;

public class Main activity Is spread AppCompatActivity {{

ImageButton imageButton;

/ **

* Maintain URI image for cropping URI if specific permission is required

* /

Private to hate mCropImageUri;

@Override

Protected Zero Go ahead()Bundle saveInstanceState) {{

Super.Go ahead()saveInstanceState);

setContentView()R.Layout.activity_main);

imageButton = ()ImageButton) findViewById()R.Id.quick_start_cropped_image);

imageButton.setOnClickListener()New Opinion.OnClickListener()) {{

@Override

public Zero on click()Opinion v) {{

click onSelectImage()v);

}

});

}

/ **

* Start image activity with selector.

* /

public Zero click onSelectImage()Opinion Opinion) {{

crop image.startPickImageActivity()this);

}

@Override

@Suppress()“Nupy”)

Protected Zero onActivityResult()int request code, int results, Intent The data) {{

// Pick image chaser handle result

If ()request code == crop image.PICK_IMAGE_CHOOSER_REQUEST_CODE && results == The activity.RESULT_OK) {{

to hate imageUri = crop image.getPickImageResultUri()this, The data);

// API> = 23 requires us to specifically check that we have permission to read external storage.

If ()crop image.isReadExternalStoragePimsRequired()this, imageUri)) {{

// allow requests and handle the result in onRequestPcriResult ()

mCropImageUri = imageUri;

Request()New String[]{{Clearly.Permission.READ_EXTERNAL_STORAGE}, 0);

} other {{

// No permission required or already disturbed, can start cropping image activity

startCropImageActivity()imageUri);

}

}

// handle the result of CropImageActivity

If ()request code == crop image.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {{

crop image.The activity results = crop image.getActivityResult()The data);

If ()results == RESULT_OK) {{

()()ImageButton) findViewById()R.Id.quick_start_cropped_image)).setImageURI()results.GetUri()));

Toast.Makeup()this, “Successful harvest, sample:” + results.getSampleSize()), Toast.LENGTH_LONG).Display());

} other If ()results == crop image.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {{

Toast.Makeup()this, “Crop Failed:” + results.Get()), Toast.LENGTH_LONG).Display());

}

}

}

@Override

public Zero onRequestPcriResult()int request code, String Permissions[], int[] Grant) {{

If ()mCropImageUri ! = Invalid && Grant.Length > 0 && Grant[0] == package manager.permission granted) {{

// allow required, start crop image activity

startCropImageActivity()mCropImageUri);

} other {{

Toast.Makeup()this, “Cancellation, required permission not granted”, Toast.LENGTH_LONG).Display());

}

}

/ **

* Start crop image activity for given image.

* /

Private Zero startCropImageActivity()to hate imageUri) {{

crop image.The activity()imageUri)

.setGuidelines()CropImageView.guidelines.On)

.setMultiTouchEnabled()True)

.Start()this);

}

}


Source link

About dmtechnolab

Check Also

Simplified Coding

Android Espresso Tutorial – Testing Fragment in Isolation – Android Coding by DMTechnolab

Welcome to another tutorial in the Android test series. And this post is called Android …

Leave a Reply

Your email address will not be published. Required fields are marked *