Sqlite按路径检索图像

时间:2013-11-19 12:42:27

标签: android android-camera android-sqlite

请任何人帮忙!

还有其他方法可以保存和检索图像吗?但我确定我不需要在sqlite中存储图像。我需要将文件名存储在sqlite中。按路径检索

捕捉图像          private void captureImage()          {

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        // start the image capture Intent
        startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);



    }

我还在sd卡中创建了目录,通过我的应用程序保存我捕获的图像

private static File getOutputMediaFile(int type)
                  {

        // External sdcard location

        File mediaStorageDir = new File
                (
                Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                IMAGE_DIRECTORY_NAME
                );

        // Create the storage directory if it does not exist
        if (!mediaStorageDir.exists()) 
        {
        if (!mediaStorageDir.mkdirs()) 
        {
        Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
            + IMAGE_DIRECTORY_NAME + " directory");
        return null;
        }
        }

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
                Locale.getDefault()).format(new Date());
        File mediaFile;

        if (type ==MEDIA_TYPE_IMAGE)
        {
            mediaFile = new File (mediaStorageDir.getPath()+ File.separator + "IMG_" + timeStamp + ".jpg");
        }
        else 
        {
            return null;
        }
    // TODO Auto-generated method stub
        return mediaFile;
                }

1 个答案:

答案 0 :(得分:1)

像这样覆盖OnActivityResult函数

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode==CAMERA_CAPTURE_IMAGE_REQUEST_CODE && resultCode == RESULT_OK)
    {
        // call your database helper class.fetch the imagepath.and store 
        // it into a static global string variable.
    }
}