如何将共享首选项与图像视图一起使用并发送到下一个活动

时间:2013-10-28 11:57:40

标签: android

如何从相机中选择照片并拍照并以共享偏好发送到下一个活动

这是来自功能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);

        }
    });

这是Aticity我想要结果

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

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

1 个答案:

答案 0 :(得分:0)

将ImageView Drawable转换为位图到字节Array-to Base 64并存储在Shared preference

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();