为多个请求代码设置带有捕获图像的imageview

时间:2015-04-22 10:49:51

标签: java php android database android-studio

嘿,如果有人可以提供帮助,我正在打瞌睡,我的应用程序有5个捕获图像的按钮,对于在这些请求代码中捕获的每个图像,图像需要设置为imageview,代码只设置图像中的一个请求代码?如果按下第二个请求代码,则应用程序停止运行

if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
    if (resultCode == RESULT_OK) {
        String[] projection = {};
        Cursor cursor = getContentResolver().query(fileUri, projection, null, null, null);
        int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        String capturedImageFilePath = cursor.getString(column_index_data);

        File imgFile = new  File(capturedImageFilePath);

        if(imgFile.exists()) {
            Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
            first_image.setImageBitmap(myBitmap);
        }
    } else if (resultCode == RESULT_CANCELED) {
        // user cancelled Image capture
        Toast.makeText(getApplicationContext(),
                     "No picture for your Schedule", Toast.LENGTH_SHORT)
                     .show();
    } else {
        // failed to capture image
        Toast.makeText(getApplicationContext(),
                     "Sorry! Failed to capture image", Toast.LENGTH_SHORT)
                     .show();
    }
} else if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE_2) {
    if (resultCode == RESULT_OK) {
        String[] projection = {};
        Cursor cursor = getContentResolver().query(fileUri, projection, null, null, null);
        int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        String captureImageFilePath = cursor.getString(column_index_data);

        File imgFile = new  File(captureImageFilePath);

        if(imgFile.exists()) {
            Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
            second_image.setImageBitmap(myBitmap);
        }
    }
}

0 个答案:

没有答案