Android MediaStore Crop function, how to make sele

2019-07-07 03:52发布

问题:

I'm working on a picture select/crop program and using this code below:

http://www.androidworks.com/crop_large_photos_with_android/comment-page-1#comment-969

As far as I could understand we set properties with putting extras to our intent like the code below.

In order to change selection area we need to touch the border and then arrows became visible but what I want to do is make them always visible because it is hard to make user understand that way. Instagram's Android application do it that way so I guess there is a way to do that.

Thanks.

Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
                intent.setType("image/*");
                intent.putExtra("crop", "true");
                intent.putExtra("aspectX", aspectX);
                intent.putExtra("aspectY", aspectY);
                intent.putExtra("outputX", outputX);
                intent.putExtra("outputY", outputY);
                intent.putExtra("scale", scale);
                intent.putExtra("return-data", return_data);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());

Edit / solution: Thanks to @Renard I found solution like this:

I used this gallery source code: http://gitorious.org/0xdroid/packages_apps_gallery3d/trees/3c02f2877dc2f8f0b5c01d03fa2b487c040e4000

I tried some other gallery resource code too but this one is the easiest one to maintain.

You just need to delete below if check in Highlightview.java class' draw() function:

if (mMode == ModifyMode.Grow)  

When you do that it works but the arrows are repating itself while moving and in order to avoid that you need to change moveBy() method's last line which is:

mContext.invalidate(invalRect);

with this:

mContext.invalidate();

回答1:

Yes there is a way. But it is not easy.

Check the source code of the Gallery app. In particular HighlightView.java. You will see that the method which is responsible for drawing the arrows is only called when the user touches the borders. So you need to grab the source code of the CropImage activity. include it in your App and modify the draw() method of HighlightView.java to always call drawResizeDrawables().

The benefit of this is that you can be sure that the crop intend will work across all devices, even if they have a custom Gallery which does not support the crop Intent.