In RoomDetailFragment.kt I already passed an activity and to the java file and tried to pass that with my URI "Dicom-path" from my mobile phone. There is no error but I don't know how to pass it may be in another way? so I thought intent.putExtra to give it to my java class "dicomimageview.java". It runs and works till my dicomimageview at the end from the code of onCreate. It crashed after this and just showed me a red rectangle. After this, I added the new Intent in onCreate at dicomimageview. Is he even passing the file path or is it just for the new activity and not getting access to my dicompath? Because I need to get for the new activity the code with on
protected void onActivityResult ( int requestCode, int resultCode, Intent data)
. It will transform the file into an image and can display it. But it can't even start the activity so it just showed me a white screen and doesn't go to the next activity for onActivityResult. I hope someone can help me.
Update PROBLEM is now he is showing me just a red picture -> I think it is a ACTIVITY Problem but i have to learn how to create a new activity in dicomImageViewer.java -> still failed enter image description here
RoomDetailFragment.kt
private fun startOpenFileIntent(action: RoomDetailViewEvents.OpenFile) {
val uri1 = action.uri.toString()
val dicom_ = ".DCM"
if (action.mimeType == MimeTypes.Apk) {
installApk(action)
}
else if (uri1.contains(dicom_)) {
activity?.let {
val intent2 = Intent(it, dicomImageView::class.java).apply {
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)
setDataAndType(action.uri, dicom_)
}
startActivity(intent2)
}
}
else {
openFile(action)
}
}
dicomImageView.java
public class dicomImageView extends AppCompatActivity {
// First thing: load the Imebra library
private ImageView mImageView; // Used to display the image
private TextView mTextView; // Used to display the patient name
@Override
protected void onCreate(Bundle savedInstanceState) {
System.loadLibrary("imebra_lib");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// We will use the ImageView widget to display the DICOM image
mImageView = findViewById(R.id.imageView);
mTextView = findViewById(R.id.textView);
ActivityResultLauncher<Intent> someActivityResultLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
// There are no request codes
Intent data1 = result.getData();
doSomeOperations(data1);
}
});
}
public void doSomeOperations(Intent intent) {
Uri selectedfile = intent.getData();
CodecFactory.setMaximumImageSize(8000, 8000);
InputStream stream = null;
try {
stream = getContentResolver().openInputStream(selectedfile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// The usage of the Pipe allows to use also files on Google Drive or other providers
PipeStream imebraPipe = new PipeStream(32000);
// Launch a separate thread that read from the InputStream and pushes the data
// to the Pipe.
Thread pushThread = new Thread(new PushToImebraPipe(imebraPipe, stream));
pushThread.start();
// The CodecFactory will read from the Pipe which is feed by the thread launched
// before. We could just pass a file name to it but this would limit what we
// can read to only local files
DataSet loadDataSet = CodecFactory.load(String.valueOf(intent));
// Get the first frame from the dataset (after the proper modality transforms
// have been applied).
Image dicomImage = loadDataSet.getImageApplyModalityTransform(0);
// Use a DrawBitmap to build a stream of bytes that can be handled by the
// Android Bitmap class.
TransformsChain chain = new TransformsChain();
if (ColorTransformsFactory.isMonochrome(dicomImage.getColorSpace())) {
VOILUT voilut = new VOILUT(VOILUT.getOptimalVOI(dicomImage, 0, 0, dicomImage.getWidth(), dicomImage.getHeight()));
chain.addTransform(voilut);
}
DrawBitmap drawBitmap = new DrawBitmap(chain);
Memory memory = drawBitmap.getBitmap(dicomImage, drawBitmapType_t.drawBitmapRGBA, 4);
// Build the Android Bitmap from the raw bytes returned by DrawBitmap.
Bitmap renderBitmap = Bitmap.createBitmap((int) dicomImage.getWidth(), (int) dicomImage.getHeight(), Bitmap.Config.ARGB_8888);
byte[] memoryByte = new byte[(int) memory.size()];
memory.data(memoryByte);
ByteBuffer byteBuffer = ByteBuffer.wrap(memoryByte);
renderBitmap.copyPixelsFromBuffer(byteBuffer);
// Update the image
mImageView.setImageBitmap(renderBitmap);
mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
// Update the text with the patient name
mTextView.setText(loadDataSet.getPatientName(new TagId(0x10, 0x10), 0, new PatientName("Undefined", "", "")).getAlphabeticRepresentation());
}
}
activity_dicom_image_view.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".features.home.room.detail.dicomImageView">
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:layout_margin="0dp"
android:gravity="center_vertical|fill_vertical|center_horizontal|fill_horizontal"
android:orientation="vertical"
android:padding="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="100"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="100">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_weight="1"
android:adjustViewBounds="false"
android:contentDescription="@string/image_description"
android:cropToPadding="false"
android:padding="0dp"
app:srcCompat="@color/colorprimary" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
also in the application, the activity is added in AndroidManifest.xml
<application
android:name=".VectorApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Vector.Light"
tools:replace="android:allowBackup">
<activity
android:name=".features.home.room.detail.dicomImageView"
android:exported="true" />
<!-- No limit for screen ratio: avoid black strips -->
<meta-data