Android 调用系统相册选择图片并显示
2017-10-16 10:19
435 查看
版权声明:本文为博主原创文章,转载请注明出处:http://blog.csdn.net/w18756901575
主要代码:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
xml:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2016/12/05 10:17
Demo下载地址:
http://download.csdn.net/detail/w18756901575/9701803
主要代码:
package wkk.app2; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; public class MainActivity extends AppCompatActivity { //调用系统相册-选择图片 private static final int IMAGE = 1; //所需权限 // <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onClick(View v) { //调用相册 Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, IMAGE); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //获取图片路径 if (requestCode == IMAGE && resultCode == Activity.RESULT_OK && data != null) { Uri selectedImage = data.getData(); String[] filePathColumns = {MediaStore.Images.Media.DATA}; Cursor c = getContentResolver().query(selectedImage, filePathColumns, null, null, null); c.moveToFirst(); int columnIndex = c.getColumnIndex(filePathColumns[0]); String imagePath = c.getString(columnIndex); showImage(imagePath); c.close(); } } //加载图片 private void showImage(String imaePath){ Bitmap bm = BitmapFactory.decodeFile(imaePath); ((ImageView)findViewById(R.id.image)).setImageBitmap(bm); } }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="wkk.app2.MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick" android:text="点击选择图片" /> <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2016/12/05 10:17
Demo下载地址:
http://download.csdn.net/detail/w18756901575/9701803
相关文章推荐
- Android 调用系统相册选择图片并显示
- Android调用系统相册和相机选择图片显示在界面
- Android 调用系统相册选择图片并显示
- Android调用系统相册和相机选择图片并显示在imageview中
- android调用系统相册将图片复制到指定目录下并显示复制进度
- Android调用系统相册选择图片,支持小米4云相册
- Android上传图片之调用系统拍照和从相册选择图片
- Android 拍照以及一些常用的处理,例如将图片显示到相册(包含了安卓系统6.0以上调用相机的处理)
- Android开发中调用系统相册上传图片到服务器OPPO等部分手机上出现短暂的显示桌面问题的解决方法
- android2.3选择相册图片或者调用系统照相
- android2.3选择相册图片或者调用系统照相
- Android从相册选择图片和调用系统摄像头拍照
- Android 调用系统相机拍照(适配7.0)、从图库选择图片、从数据库读取联系人信息、相册图片、扫描文件
- android中调用系统功能 来显示本地相册图片 拍照 视频 音频功能
- 【Android】调用系统相册选择图片
- 调用Android系统相册并裁剪图片
- Android 调用相册 拍照 实现系统控件缩放 切割图片 .
- android 调用系统拍照并显示拍摄后的原图片
- Android 调用相册 拍照 实现系统控件缩放 切割图片
- Android调用相机或选择相册后加载图片内存不足