I am using the following sample code, https://github.com/mklimek/android-crop/tree/newfeature_fied_size_crop . It is giving the fixed size cropping view(ie, HighlightView). But the problem is this highlightView is fixed depends on Uploaded image. Below are the screen shots with two different size uploaded images.
I used below lines of code to fix the size of the HighlightView:
private void beginCrop(Uri source) {
Uri outputUri = Uri.fromFile(new File(getCacheDir(), "cropped"));
new Crop(source).output(outputUri).asRectangle().withFixedSize(100, 210).start(this);
}
withFixedSize() method is used to fix the size of the cropped area , we cannot resize that view if we use this method, that is fine. But That cropped area should be fixed with width=100, height=210,It should not change depends the uploaded image.
Big size uploaded image has a small size of crop view (ie, HighlightView):
Small size uploaded image has a large size of crop view (ie, HighlightView):
My requirement is I have to fix the size of cropped area, I should not resize that. I searched in google world. But I didn't found solution.
Please help me on this.
visit this : https://github.com/jdamcd/android-crop
Crop
Crop.of(inputUri, outputUri).asSquare().start(activity)
Listen for the result of the crop (see example project if you want to do some error handling):
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
if (requestCode == Crop.REQUEST_CROP && resultCode == RESULT_OK) {
doSomethingWithCroppedImage(outputUri);
}
}
Some attributes are provided to customise the crop screen. See the example project theme.
Pick
The library provides a utility method to start an image picker:
Crop.pickImage(activity)
Dependency
The AAR is published on Maven Central:
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
Java code :
public class MainActivity extends Activity {
private ImageView resultView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultView = (ImageView) findViewById(R.id.result_image);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_select) {
resultView.setImageDrawable(null);
Crop.pickImage(this);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
if (requestCode == Crop.REQUEST_PICK && resultCode == RESULT_OK) {
beginCrop(result.getData());
} else if (requestCode == Crop.REQUEST_CROP) {
handleCrop(resultCode, result);
}
}
private void beginCrop(Uri source) {
Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"));
Crop.of(source, destination).asSquare().start(this);
}
private void handleCrop(int resultCode, Intent result) {
if (resultCode == RESULT_OK) {
resultView.setImageURI(Crop.getOutput(result));
} else if (resultCode == Crop.RESULT_ERROR) {
Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
Output :
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.