Example #1
0
        public Bitmap LoadBitmap(string fileName)
        {
            try
            {
                // we should either have a fileName or dataset
                if (fileName != null && fileName.Length > 0)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    try
                    {
                        dicom = OtherImageFormats.Read(fileName);
                    }
                    finally
                    {
                        //SetStatus("");
                        Cursor.Current = Cursors.Default;
                    }
                }
                if (dicom == null)
                {
                    throw new ArgumentException("No fileName or dataset.");
                }

                return(LoadBitmap(dicom));
            }
            catch (Exception ex)
            {
                MessageBox.Show(Logging.Log(ex));
            }

            return(null);
        }
Example #2
0
        private void LoadFile(string fileName)
        {
            try
            {
                var elements   = OtherImageFormats.Read(fileName);
                var isDicomDir = elements.GetSafeStringValue(t.MediaStorageSOPClassUID) ==
                                 SOPClass.MediaStorageDirectoryStorage;

                var receivedDicom = new ReceivedDicomElements
                {
                    CallingAeTitle = "Localhost",
                    FileName       = fileName,
                    Elements       = elements,
                    ImageSource    = isDicomDir? ImageSource.LocalDicomDir : ImageSource.LocalDicomFile,
                    SavedToDisk    = true
                };

                ShowElements(receivedDicom);

                ShowMessage(fileName + " opened successfully!", false, false);
            }
            catch (Exception ex)
            {
                ShowMessage(fileName + " opened failed! " + ex.Message, true, true);
            }
        }
Example #3
0
        private Bitmap GetPicture()
        {
            //PictureBox.Location = new Point(0, 0);
            //PictureBox.Size = ClientRectangle.Size;

            ImageAttributes cropped = attributes; // OtherImageFormats.Crop(attributes);
            // if the application is minimized, PictureBox.Size has zero dimensions
            //Size size = new Size();
            //size.Height = 1000;
            //size.Width = 1000;

            //if (size.Width == 0 || size.Height == 0)
            //{
            //    // when the window is resized, we will render another image for display
            //    PictureBox.Image = null;
            //    return;
            //}

            //size = OtherImageFormats.Constrain(new Size(cropped.width, cropped.height), size);

            var             size      = new Size(cropped.width, cropped.height);
            ImageAttributes resampled = (cropped.bitsperpixel == 8) ?
                                        cropped : Utilities.Resample(cropped, (double)attributes.width / (double)size.Width);

            ushort[] planes = null;
            if (overlays && overlay != null)
            {
                ImageAttributes source = new ImageAttributes();
                source.type   = TypeCode.UInt16;
                source.buffer = overlay;
                source.width  = attributes.width;
                source.height = attributes.height;
                source.stride = attributes.width;
                // attributes.spacing = ;
                source.bitsperpixel = 12;
                source.monochrome1  = true;

                //ImageAttributes temp = Utilities.Resample(source, (double)attributes.width / (double)size.Width);
                planes = (ushort[])source.buffer;
            }

            Bitmap bitmap = OtherImageFormats.GetBitmap(resampled, planes, voilut, invert);

            Bitmap final = (bitmap.Size != size) ? new Bitmap(bitmap, size) : bitmap;

            SurroundMask(final);

            return(final);
        }
Example #4
0
        private void treeListView_DicomDir_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (treeListView_DicomDir.SelectedNodes.Count != 1)
            {
                return;
            }

            var fileId = treeListView_DicomDir.SelectedNodes[0].AdditionalData as Element;

            if (fileId == null)
            {
                return;
            }

            var filePath = fileId.Value as string[];

            if (filePath == null)
            {
                return;
            }

            var inDicomDirPath = filePath.Aggregate(string.Empty, (current, s) => current + ("\\" + s));
            var fullPath       = receivedDicomElements.FileName + inDicomDirPath;

            try
            {
                var elements      = OtherImageFormats.Read(fullPath);
                var receivedDicom = new ReceivedDicomElements
                {
                    CallingAeTitle = "Localhost",
                    FileName       = fullPath,
                    Elements       = elements,
                    ImageSource    = ImageSource.LocalDicomFile,
                    SavedToDisk    = true
                };

                ShowElements(receivedDicom, inDicomDirPath);

                dicomServiceWorkerUser.ShowMessage(fullPath + " opened successfully!", false, false);
            }
            catch (Exception ex)
            {
                dicomServiceWorkerUser.ShowMessage(fullPath + " opened failed! " + ex.Message, true, true);
            }
        }
Example #5
0
        private void OnImagePrinted(object sender, PrintJobEventArgs e)
        {
            var message  = string.Empty;
            var hasError = true;

            try
            {
                var page     = e.Session.FilmBoxes[0];
                var elements = OtherImageFormats.RenderPage(page);

                var receivedDicomElements = new ReceivedDicomElements
                {
                    CallingAeTitle     = e.CallingAeTitle,
                    CallingAeIpAddress = e.CallingAeIpAddress,
                    ReceivedDateTime   = DateTime.Now,
                    Elements           = elements,
                    ImageSource        = ImageSource.Print,
                    ImageStatus        = dicomServiceWorkerUser.OpenWhenReceived() ? ImageMemoryStatus.OpenedInWindow : ImageMemoryStatus.CachedInMemory
                };

                message = string.Format("AeTitle : {0}, IpAddress : {1}", receivedDicomElements.CallingAeTitle, receivedDicomElements.IpAddress);

                OnDicomElementsReceived(receivedDicomElements);

                message  = "Print successfull! -- " + message;
                hasError = false;
            }
            catch (Exception ex)
            {
                message = "Print failed! -- " + message + "  " + ex.Message;
            }
            finally
            {
                dicomServiceWorkerUser.ShowMessage(message, hasError, false);
            }
        }