3

I am trying to integrate Imebra library to load .dcm files inside the app. The problem is that as per the documentation, I need to pass the absolute path of the file to Imebra as shown below:

val loadDataSet = CodecFactory.load("myFile.dcm")

For opening the DCM files, I am using the below code:

 val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
                addCategory(Intent.CATEGORY_OPENABLE)
                type = "*/*"
                putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
            }

            startActivityForResult(intent, RC_OPEN_FILES)

I am able to get the list of URI's for all the selected files using the below code:

 if (data != null) {
                val clipData = data.clipData
                if (clipData != null) {
                    // Multiple files selected
                    val clipDataUriList = arrayListOf<Uri>()
                    for (i in 0 until clipData.itemCount) {
                        clipDataUriList.add(clipData.getItemAt(i).uri)
                    }
                    processDcmFiles(clipDataUriList)
                } else {
                    // Single file selected
                    data.data?.let { processDcmFiles(arrayListOf(it)) }
                }

            }

I tried using uri.getPath() and creating a File using the URI and then getting the absolute path but none of them seems to work.

I am not sure if this the right approach to get the absolute path of the files in Android 10. Any help will be appreciated.

Mehul Kanzariya
  • 888
  • 3
  • 27
  • 58
  • That was a false approach. You will not try to get a path from an uri. What you can do however when you need a file path is to make a copy to the file system first and then use the path of the copied file. – blackapps Mar 02 '20 at 11:14
  • @blackapps Can you please attach some links that shows how to do this? – Mehul Kanzariya Mar 02 '20 at 11:15
  • It appears that you do not read this site at all as your problem has been reported here twice a day the last months, Please read. – blackapps Mar 02 '20 at 11:16
  • But open an input stream for the obtained uri and an output stream for a file path of choice. Then read from the input and writethat to the output. It's about the same as copying a classic file. – blackapps Mar 02 '20 at 11:26
  • Okay, I will try this. Thanks :) – Mehul Kanzariya Mar 02 '20 at 11:27
  • this answer worked for me for all my case: https://stackoverflow.com/a/63032934/12401637 – gowtham6672 Jul 22 '20 at 12:16

1 Answers1

0

This sample app uses the file selector to open and display a file: https://github.com/binarno/Imebra-V5-Android-Simple-Dicom-Viewer

The app delegates the opening and loading of the file (if necessary) to Android, then passes the file to Imebra via the Imebra Pipes.

While slightly more complex, it allows Imebra to read files also from external sources (e.g. Google Drive).

Disclaimer: I'm the author of Imebra

Paolo Brandoli
  • 4,681
  • 26
  • 38
  • I already have gone through the code of this sample. The problem is that I am using the old version of Imebra which doesn't support this. The reason for using the old version is because I am unable to apply transformations in the latest version. – Mehul Kanzariya Mar 02 '20 at 11:19
  • As per the docs, the code for applying transformations includes initializing VOILUT() class without passing any parameters but the same code shows an error when used with the latest version and asks for the parameters to be passed in the constructor. – Mehul Kanzariya Mar 02 '20 at 11:26
  • Also, the line voilutTransform.setCenterWidth(vois.get(0).center, vois.get(0).width); shows the error. I was unable to solve these errors and hence tried the different approach to get the absolute path from the uri. – Mehul Kanzariya Mar 02 '20 at 11:28
  • 1
    VOIs vois = loadDataSet.getVOIs(); // Get a list of contrast settings from the dataset if(!vois.isEmpty()) { VOILUT transform = new VOILUT(vois.get(0)); }// Use the first contrast setting. This is in the documentation for Imebra 5 (which differs from Imebra 4) – Paolo Brandoli Mar 02 '20 at 12:01
  • Why dont you add a member function to load from stream? And/Or load from uri? Then a normal content uri obtained from Intent.ACTION_OPEN_DOCUMENT could be used right away. Addng such a possibility should not be much work as you will open a stream for a file path too already. – blackapps Mar 02 '20 at 12:33
  • @blackapps The library is written completely in C++, the Java wrapper is automatically generated by Swig. – Paolo Brandoli Mar 02 '20 at 12:37
  • And a java input stream can not be used by C++? – blackapps Mar 02 '20 at 12:43
  • @PaoloBrandoli Thank a lot. The solution in the comment worked. I have been trying to solve this for 3 days :) – Mehul Kanzariya Mar 02 '20 at 12:47