Android ImageView implements image clipping and display functions

First, set the button and an ImageView in the layout

Write code on activity

The method of implementing onclicklistener and setting the method of clipping pictures

If you want to get the data returned after the newly opened activity is closed in the activity, you need to use the startactivityforresult (intent, int requestcode) method provided by the system to open the new activity. After the new activity is closed, it will return data to the previous activity. In order to get the returned data, you must rewrite onactivityresult in the previous activity (int requestcode, int resultcode, intent data) method

When the new activity is closed, the data returned by the new activity is transmitted through intent. The Android platform will call the onactivityresult() method of the previous activity and pass in the intent storing the returned data as the third input parameter. The data returned by the new activity can be retrieved by using the third input parameter in the onactivityresult() method.

If you need to return data or results, use startactivityforresult (intent, int requestcode). The value of requestcode is user-defined and is used to identify the target activity to jump.

Override onactivityresult method

When we analyze an image, if it is too large, it will oom. We can set the compression ratio insamplesize, but how much the compression ratio is set is a problem. Therefore, we can analyze the image in two steps. The first step is to obtain the width and height of the image. Here, set options. Injustdecodeboundaries = true. At this time, the bitmap of the decode is null, Just put the width and height of the picture in options.

Then the second step is to set the appropriate compression ratio insamplesize. Insamplesize is the original 1 / ratio. At this time, an appropriate bitmap is obtained.

Set options.injustdecodebounds = false; Reread the picture bitmap = bitmapfactory. Decodestream (getcontentresolver(). Openinputstream (URI), options);

The above is what Xiaobian introduced to you. Android ImageView realizes the function of image clipping and display. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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