2015-04-22 79 views
1

我想知道如果有人可以幫助我,我的應用程序當前使用多個捕獲圖像按鈕拍攝照片,我想要獲取每個圖像的文件路徑並將其保存到數據庫。我將如何去做這件事。我嘗試使用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(); 

回答

1

有你需要遵循的步驟,您需要在onActivityResult()意圖開幕前通過形象的名字

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

然後

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); 
+0

哎所以將文件路徑該圖像位於捕獲的圖像文件路徑,然後我會得到該字符串保存到我的數據庫? – user3461038

+0

是的確切.... –

+0

只是爲了undertsand爲什麼我需要傳遞圖像的名稱? – user3461038

相關問題