Android takes a picture or selects a picture from the gallery and cuts it

Today, I looked at the part about taking photos and selecting pictures from the album in the first line of code. I found that there was always no effect, so I searched other materials to learn relevant knowledge and wrote a simple demo.

1、 Take pictures select pictures

1. Start camera with implicit intent

2. Process the results returned by the camera

2、 Select pictures from Gallery

1. Build content selection implicit intent

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

2. Set content type to picture

intent. setType("image/*");

3. Start picture selection

startActivityForResult(intent,2);

4. Process picture selection results

3、 Crop selected picture

The bitmap type is obtained from the camera, so we need to convert it into a file URI for clipping. At the same time, we have to save the photos taken by the camera locally.

The image selected from the gallery returns a URI of content type. We need to convert it to a URI of file type for clipping.

The following is to set the parameters of clipping and start the clipping program in an implicit intent mode

The following is the complete layout file and Java file

--------------------------------------------------------------------------------

activity_ main. XML file

MainActivity. Java file

Note: finally, you need to add the memory card read-write permission to the androidmanifest file

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>