This is a very narrow and specific question, but I know there are someone else out there using this, so I\'ll keep my fingers crossed and hope anyone of you pics this questi
Okay, I figured it out.. There might be some more ways of achieving this, but this is what I did. Now I have a Wpf Image bound to a property which provides the bitmap data. The following is the property used to provide the Bitmap data.
public BitmapSource CurrentFrameData
{
get
{
LocalSopDataSource _dicomDataSource =
new LocalSopDataSource(_dicomFilePath);
var imageSop = new ImageSop(_dicomDataSource);
IPresentationImage presentationImage =
PresentationImageFactory.Create(imageSop.Frames[CurrentFrame]);
int width = imageSop.Frames[CurrentFrame].Columns;
int height = imageSop.Frames[CurrentFrame].Rows;
Bitmap bmp = presentationImage.DrawToBitmap(width, height);
BitmapSource output = Imaging.CreateBitmapSourceFromHBitmap(
bmp.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight(width, height));
return output;
}
}
Note that this is a very straight forward solution. One might e.g. want to do stuff like preloading the pictures etc to avoid heavy load when scrolling multiframe images. But for the "howto display the image" question - this should answer it..
Ok, I've managed to show a DICOM image in a Picturebox using this code:
Here are the assemblies I used:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ClearCanvas.Common;
using ClearCanvas.Dicom;
using System.Windows.Media.Imaging;
using ClearCanvas.ImageViewer;
using ClearCanvas.ImageViewer.StudyManagement;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows;
using System.IO;
I also had to copy these dll into bin/debug:
BilinearInterpolation.dll (this one I could'nt reference it as assemblie so I just copied it into the bin/degug folder)
WindowsBase.dll (This one I was able to reference it as an assemblie)
Code (There's a button in my project that lets you select the dcm file and then show it in a picturebox)
Private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "DICOM Files(*.*)|*.*";
if (ofd.ShowDialog() == DialogResult.OK)
{
if (ofd.FileName.Length > 0)
{
var imagen = new DicomFile(ofd.FileName);
LocalSopDataSource DatosImagen = new LocalSopDataSource(ofd.FileName);
ImageSop imageSop = new ImageSop(DatosImagen);
IPresentationImage imagen_a_mostrar = PresentationImageFactory.Create(imageSop.Frames[1]);
int width = imageSop.Frames[1].Columns;
int height = imageSop.Frames[1].Rows;
Bitmap bmp = imagen_a_mostrar.DrawToBitmap(width, height);
PictureBox1.Image = bmp;
imageOpened = true;
}
ofd.Dispose();
}
}