Android - 将图片路径保存到本地数据库

时间:2011-10-24 12:18:36

标签: android database uri sd-card image

我的目标是使用标准相机拍照并将其路径保存到本地数据库。我有以下内容:

Classvariables:

private static final int IMAGE_CAPTURE = 0;
private Uri imageUri;
private ImageView imageView;

Button takePhotoButton;

的onCreate:

imageView = (ImageView)findViewById(R.id.img);
imageView.setVisibility(View.GONE);

takePhotoButton = (Button) findViewById(R.id.takePhoto);

监听器(按钮):

takePhotoButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                takePhoto();
            }
        });

拍摄照片的功能:

private void takePhoto(){
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/png");
        imageUri = getContentResolver().insert(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, IMAGE_CAPTURE);
    }

和回调:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == IMAGE_CAPTURE) {
            if (resultCode == RESULT_OK){

                imageView.setImageURI(imageUri);
                imageView.setVisibility(View.VISIBLE);
            }
        }
    }

现在,我的照片是/ sdcard / DCIM / Camera /

我的问题:

如何在本地数据库中将这些图片的路径(类型URI)保存为字符串?

MFG 戴夫

0 个答案:

没有答案