繁体   English   中英

如何获取捕获的图像文件路径并保存到数据库?

[英]how to get Captured image filepath and save to database?

我想知道是否有人可以帮助我,我的应用程序当前使用多个捕获图像按钮拍摄照片,我想获取拍摄的每个图像的文件路径并将其保存到数据库中。 我将如何去做。 我尝试使用string name = fileuri.getpath将其保存到数据库中,但是没有给出所拍摄图像的确切目的地。

else if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE_2) {

             if (resultCode == RESULT_OK) {

                String second_imagePath = fileUri.getPath();
                 BitmapFactory.Options options = new BitmapFactory.Options();
                 // down sizing image as it throws OutOfMemory Exception for larger
                 // images
                 options.inSampleSize = 8;
                 final Bitmap bitmap = BitmapFactory.decodeFile(second_imagePath, options);
                 second_image.setImageBitmap(bitmap);

                 Toast.makeText(getApplicationContext(),
                         second_imagePath, Toast.LENGTH_SHORT)
                         .show();

您需要遵循一些步骤,需要在打开意图之前传递图像名称

 String fileName = "some.jpg";  
 ContentValues values = new ContentValues();  
 values.put(MediaStore.Images.Media.TITLE, fileName);  
 mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  

 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
 intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);  
 startActivityForResult(intent, CAPTURE_PICTURE_INTENT);

然后在onActivityResult()

Cursor cursor = managedQuery(mCapturedImageURI, projection, null, null, null); 
int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
cursor.moveToFirst(); 
String capturedImageFilePath = cursor.getString(column_index_data);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM