前几天做一个小玩意的时候需要从本地获取图片,在网上查了半天发小好多种方法,现在就和大家分享一种我觉得很简单的方法。
为了更好的理解,我自己建了一个工程来展示这个功能,效果图如下:
点击确认后就可以将自己剪切的好的图片显示在ImageView中,效果图如下:
好了,不多说了,开始上代码,首先是布局文件代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView1"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:layout_height="wrap_content"
android:layout_width&