如何调用andorid本地图库并获取其图片路径

如何调用android本地图库:

使用Intent实现页面跳转,到本地图库界面(如点击按钮bt1实现页面跳转至图库):

public void bt1(View view){
<span style="white-space:pre">		</span> Intent intent = new Intent(Intent.ACTION_PICK,
                 android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
         startActivityForResult(intent,0);
<span style="white-space:pre">	</span>}

然后获取点击图片的路径:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(data!=null){
			if(requestCode==0&&resultCode==Activity.RESULT_OK){
				Uri selectedImage =data.getData();
				String [] filePathColumn={MediaStore.Images.Media.DATA};
				 Cursor cursor = getContentResolver().query(selectedImage,
	                        filePathColumn, null, null, null);
				 cursor.moveToFirst();
	             int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
	             String picPath = cursor.getString(columnIndex);
	             cursor.close();
	             if(picPath.equals("")) return;
	             Intent intent = new Intent(this, Function1.class);
	             Bundle bundle =new Bundle();
	 	     bundle.putString("imagePath",picPath);
	 	     intent.putExtras(bundle);
	             startActivity(intent);
			}

	}
把图片的路径通过Bundle进行传递给其他Activity并显示:
                Intent intent =getIntent();
		Bundle bundle =intent.getExtras();
		String imagePath=bundle.getString("imagePath");
	        bitmap =BitmapFactory.decodeFile(imagePath);
<span style="white-space:pre">		</span>mImageView.setImageBitmap(bm);





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值