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;
                }

像这个一样覆盖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.
    }
}

最新更新