Android 实现拍照和调用相册取多张图片,以下只展示两张图片


一、使用:https://github.com/lovetuzitong/MultiImageSelector,实现拍照和调用相册功能,得到多张图片地址。
二、展示两张图片
总结:调用相册没记忆功能,展示多张图片可在步骤二自行修改实现

Android 实现拍照和调用相册取多张图片,以下只展示两张图片_第1张图片

Android 实现拍照和调用相册取多张图片,以下只展示两张图片_第2张图片
**

步骤一:拍照和调用相册,获取多张图片地址

**

https://github.com/lovetuzitong/MultiImageSelector
下载里面的文件 multi-image-selector,添加到自己的工程中。

1、android studio 导入Module并添加依赖
导入:File–>New–>Import Module
依赖:File–>Project Structure–>app–>Dependencies–>点击加号,选第三个
2、权限

    name="android.permission.READ_EXTERNAL_STORAGE" />
    name="android.permission.WRITE_EXTERNAL_STORAGE" />


  <application

        "orientation|screenSize"
            android:name="me.nereo.multi_image_selector.MultiImageSelectorActivity" />
    application>
3、点击控件,打开相册,获取图片地址
         Intent intent=new Intent(mContext, MultiImageSelectorActivity.class);
        // 是否显示调用相机拍照
        intent.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA,true);
        //设置获取最大图片数量
        intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_COUNT,2);
        // 设置模式(单选 MODE_SINGLE /多选MODE_MULTI)
        intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE,MultiImageSelectorActivity.MODE_MULTI);
        startActivityForResult(intent,REQUEAT_CODE);
4、在回调函数onActivityResult()方法中,处理返回的数据
  switch (requestCode){
            //图片返回
            case REQUEAT_CODE:
                if (data!=null){
                    ArrayList<String> mSelectPath = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
                    //得到照片的路径,以下处理具体逻辑
结论:可以从相册得到多张图片的地址。

**

步骤二:展示两张图片

**

 以下为具体逻辑
    for (int i=0;i
                        if (i==0&& rela_up_picture1.getVisibility()==View.GONE){
                            Bitmap bt = BitmapFactory.decodeFile(mSelectPath.get(i).toString());
                            iv_up_picture1.setImageBitmap(ThumbnailUtils.extractThumbnail(bt,100,80));
                            rela_up_picture1.setVisibility(View.VISIBLE);
                            tv_remember_path1.setText(mSelectPath.get(i).toString());
                        }else if (i==0&& rela_up_picture1.getVisibility()==View.VISIBLE){
                            Bitmap bt = BitmapFactory.decodeFile(mSelectPath.get(i).toString());
                            iv_up_picture2.setImageBitmap(ThumbnailUtils.extractThumbnail(bt,100,80));
                            rela_up_picture2.setVisibility(View.VISIBLE);
                            iv_up_picture.setVisibility(View.GONE);
                            tv_remember_path2.setText(mSelectPath.get(i).toString());
                        } else if (i==1){
                            Bitmap bt = BitmapFactory.decodeFile(mSelectPath.get(i).toString());
                            iv_up_picture2.setImageBitmap(ThumbnailUtils.extractThumbnail(bt,100,80));
                            rela_up_picture2.setVisibility(View.VISIBLE);
                            iv_up_picture.setVisibility(View.GONE);
                            tv_remember_path2.setText(mSelectPath.get(i).toString());
                        }else if (i==0&& rela_up_picture2.getVisibility()==View.VISIBLE){
                            Bitmap bt= BitmapFactory.decodeFile(mSelectPath.get(i).toString());
                            iv_up_picture1.setImageBitmap(ThumbnailUtils.extractThumbnail(bt,105,70));
                            rela_up_picture1.setVisibility(View.VISIBLE);
                            iv_up_picture.setVisibility(View.GONE);
                            tv_remember_path1.setText(mSelectPath.get(i).toString());
                        }

                        if (rela_up_picture2.getVisibility() == View.VISIBLE) {
                            btn_up_delete1.setVisibility(View.GONE);
                        }else {
                            btn_up_delete1.setVisibility(View.VISIBLE);
                        }
                    }
布局是三张图片,后两张用于展示。
步骤二是我自己写的,暂时还没发现问题,有需要的可以找我。

你可能感兴趣的:(android)