0

我如何选择照片并从相机拍照并发送到具有共享偏好的下一个活动

这是来自功能 camara

btncamera.setOnClickListener(new OnClickListener() {
        @SuppressLint("SimpleDateFormat")
        public void onClick(View v) {
            SharedPreferences app_preferences =
                    PreferenceManager.getDefaultSharedPreferences(Showpic_resumeActivity.this);
                    SharedPreferences.Editor editor = app_preferences.edit();

                    String imageview_re = imageView1.getContext().toString();
                    editor.putString("key6", imageview_re);

            Intent intentcamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            String imageFileName = "IMG_" + timeStamp + ".jpg";
            File f = new File(Environment.getExternalStorageDirectory(), "DCIM/Camera/" + imageFileName);
            uri = Uri.fromFile(f);



            intentcamera.putExtra(MediaStore.EXTRA_OUTPUT, uri);

            startActivityForResult(Intent.createChooser(intentcamera, "Take a picture with"), REQUEST_CAMERA);
            editor.commit();

            Intent myIntent = new Intent(Showpic_resumeActivity.this,Showdata_result_resume.class);
            startActivity(myIntent);

        }
    });

这是我想要的结果

SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
     String imgview_resume = app_preferences.getString("key6", "null");
        imageresume.set(imgview_resume);

我有错误这一行 imageresume.set(imgview_resume); 我应该使用 .set 吗?

4

1 回答 1

0

将 ImageView Drawable 转换为位图到字节数组到 Base 64 并存储在共享首选项中

BitmapDrawable drawable = (BitmapDrawable) iv.getDrawable();
Bitmap bmap= drawable.getBitmap();
ByteArrayOutputStream bos = new ByteArrayOutputStream();  
bmap.compress(CompressFormat.PNG,100,bos); 
byte[] bb = bos.toByteArray();
String image =Base64.encodeToString(bb, Base64.DEFAULT).trim();
于 2013-10-28T12:07:43.580 回答