android 点击一个按钮,选择一张图片,获取路径,然后显示在屏幕

// 请在点击事件中调用此函数
int REQUEST_CODE_SELECT_PIC = 120;
private void selectPicture() {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_PICK);
        intent.setType("image/*");
        // 这个函数会自动调用下面的函数
        startActivityForResult(intent, REQUEST_CODE_SELECT_PIC);
    }

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == REQUEST_CODE_SELECT_PIC) {

            // 获取选择的图片
            Uri selectedImage = data.getData();
            int width = 0;
            int height = 0;

            String[] filePathColumn = { MediaStore.Images.Media.DATA };
            Cursor cursor = getContentResolver().query(selectedImage, null,
                    null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            // 获取到图片的路径
            String selectedImagePath = cursor.getString(columnIndex);

            Log.e("zhangxin selectedImagePath", selectedImagePath);
            // 调取底层处理
            //DealImage(selectedImagePath);
            // 解码该路径的图片,得到bitmap 图片
            bm = BitmapFactory.decodeFile(mRootResult + "result.bmp");

            width = bm.getWidth();
            height = bm.getHeight();
            {
                // 字符串的操作
                int satrt = selectedImagePath.toString().lastIndexOf("/");
                int end = selectedImagePath.toString().lastIndexOf(".");
                // 文件路径 ; 文件全路径+名字
                ImagePath = selectedImagePath.toString().substring(0, satrt);
                Log.e("zhang ImagePath", ImagePath);
            }
            if (selectedImage != null) {
                //将图片显示到ImageView中
                mImageView.setImageBitmap(bm);

            }

        }
        super.onActivityResult(requestCode, resultCode, data);
    }
    [你可以直接下载一个jni 通过点击图片,底层处理完,然后显示在屏幕]   http://download.csdn.net/detail/baidu_31872269/9768004

你可能感兴趣的:(android)