• Android 获得选择的系统相册图片


    public void onActivityResult(int requestCode, int resultCode,
                final Intent data) {
            if (RESULT_OK == resultCode && 1 == requestCode) {
                LayoutInflater inflater = getLayoutInflater();
                View layout = inflater.inflate(R.layout.dialog,
                        (ViewGroup) findViewById(R.id.dialog));
    
                Builder mydialog = new AlertDialog.Builder(ImChoose.this);
                mydialog.setView(layout);
                iv = (ImageView) layout.findViewById(R.id.iv);
                uri = data.getData();
                ContentResolver cr = this.getContentResolver();
                try {
                    bm = BitmapFactory.decodeStream(cr.openInputStream(uri));
                    iv.setImageBitmap(bm);
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                mydialog.setPositiveButton("确定", new OnClickListener() {
    
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        // iv1.setImageURI(uri);
                        iv1.setImageBitmap(bm);
                    }
    
                });
    
                // 设置重写重新选择键
                mydialog.setNeutralButton("重新选择", new OnClickListener() {
    
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        Intent intent = new Intent();
                        intent.setType("image/*");
                        intent.setAction(intent.ACTION_GET_CONTENT);
                        startActivityForResult(intent, 1);
    
                    }
                });
                mydialog.setNegativeButton("取消", new OnClickListener() {
    
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        Toast.makeText(ImChoose.this, "cancel", Toast.LENGTH_SHORT)
                                .show();
    
                    }
                });
    
                mydialog.create();
                mydialog.show();
            }
            super.onActivityResult(requestCode, resultCode, data);
        }
  • 相关阅读:
    Matlab——m_map指南(4)——实例
    Python——matplotlib基础绘图函数示例
    Python——Matplotlib库入门
    Python——图像手绘效果
    MATLAB——nctoolbox安装及使用
    Python——NumPy库入门
    Failed to connect to github.com port 443: Timed out
    python 调用C++ DLL,传递int,char,char*,数组和多维数组
    python基础
    linux常用命令
  • 原文地址:https://www.cnblogs.com/merryjd/p/2832226.html
Copyright © 2020-2023  润新知