Android calls system cropping, this is already very familiar. However, I encountered some minor problems when using the project recently, so I sorted it out here to record it.
First look at the code:
Intent intent1 = new Intent(""); ((new File()), "image/*"); ("crop", "true"); (MediaStore.EXTRA_OUTPUT, (tempFile));// ("aspectX", 1); ("aspectY", 1); ("outputFormat", ); ("outputX", 720); ("outputY", 720); ("return-data", false); startActivityForResult(intent1, 0x222);
This is the part before the modification. It seems that there is no problem and the cropping can be done normally. Moreover, the output size 720*720 is already relatively small, but the problem arises. When only a small piece is used to crop the picture, a black frame appears around the picture.
At the beginning, I didn’t understand how the black box was added, but later it was processed by the server (the pictures uploaded by the server on many servers were compressed, and thumbnails were generally displayed). But after careful inspection, I found that the picture had a black frame before I uploaded it, so the problem naturally lies with me.
After checking a lot of information, I finally found the problem. Because when cropping large or high-definition images, no matter how small they are, there will be no black frames. This naturally leads to the automatic filling of edges after cropping.
Once you know the problem, it will be easy to solve it, and then look for the solution. Just like the idea, it is to do fill and stretch when the picture is too small after it is cropped. Later I found this property, like this:
("scale", true); ("scaleUpIfNeeded", true);
I won't explain it here. The English codes have practical meanings and can be understood almost by looking at the literal meaning.
After using these two important attributes, my cropping method is OK. After modification, the code is as follows:
Intent intent1 = new Intent(""); ((new File()), "image/*"); ("crop", "true"); (MediaStore.EXTRA_OUTPUT, (tempFile));// ("aspectX", 1); ("aspectY", 1); ("outputFormat", ); ("outputX", 720); ("outputY", 720); ("scale", true); ("scaleUpIfNeeded", true); ("return-data", false); startActivityForResult(intent1, 0x222);
Because this sentence is added to the code:
(MediaStore.EXTRA_OUTPUT, (tempFile));//
That is, the target file is specified, so you can use tempFile directly in onActivityResult.
The above method of implementing Android calling system cropping is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.