Examples of Android settings for taking photos or uploading local pictures

A few days ago, our client received a demand from the marketing department. After our order is completed, our client has the function of uploading transaction vouchers. So how to realize the function of uploading pictures on Android? Before I code, I ask myself a few questions.

First, is the picture directly selected from the gallery, or do you need to take pictures and select pictures?

Because when selecting pictures, there will be a button to take pictures, which can also realize the function of taking pictures.

Second, do you need a local cache?

The value of local cache is whether our pictures will be displayed directly next time after uploading, rather than read from the server.

Third, does the picture need to be compressed?

As we all know, pictures are a kind of resource. Because of their large size, the transmission on the network is still very slow. Therefore, we need to properly compress the file size during our transmission, so we need to compress it according to a certain proportion according to our own needs.

After thinking about these issues, according to our own needs, we have two options when uploading, one is to take photos, the other is to select pictures, in addition, we need to do local caching, and there is no need to compress pictures when uploading.

Then we can start to implement it. First, add the following code in our main fragment. If you are an activity, of course.

Make an ImageView as the image we uploaded.

Then, we jump to another popupactivity and let's choose popupactivity. Java

Popup.xml

Next, we need to add onactivityresult to our main fragment (or activity)

In addition, the code for processing image upload is here.

Then it's OK. Our final effect is as follows.

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
分享
二维码
< <上一篇
下一篇>>