Ejemplo n.º 1
0
        public static FreeImageAlgorithmsBitmap LoadFreeImageBitmapFromFile(string filepath)
        {  // This method is independant of Tile
            IcsFile icsFile;
            FreeImageAlgorithmsBitmap fib = null;

            try
            {
                if (IcsFile.IsIcsFile(filepath))
                {
                    icsFile = new IcsFile(filepath);
                    fib     = icsFile.FreeImageAlgorithmsBitmap;
                    icsFile.Close();
                }
                else
                {
                    fib = new FreeImageAlgorithmsBitmap(filepath);
                }
            }
            catch (Exception e)
            {
                throw;
            }

            // Resample seems to only work for uint16 not int16 currently
            if (fib.ImageType == FREE_IMAGE_TYPE.FIT_INT16)
            {
                fib.ConvertInt16ToUInt16();
            }

            return(fib);
        }
Ejemplo n.º 2
0
        private void SaveScreenShot()
        {
            string filePath = Utilities.SaveDialog(true);

            if (filePath == null)
            {
                return;
            }

            Bitmap   bitmap = this.imageView.ScreenBitmap;
            Graphics g      = Graphics.FromImage(bitmap);

            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;

            OnSavingScreenShot(g, new MosaicWindowEventArgs(MosaicWindow.MosaicInfo));

            FreeImageAlgorithmsBitmap fib = new FreeImageAlgorithmsBitmap(bitmap);

            fib.ConvertTo24Bits();

            g.Dispose();

            bitmap.Dispose();

            string extension = Path.GetExtension(filePath);

            if (extension != ".ics")
            {
                fib.SaveToFile(filePath);
            }
            else
            {
                IcsFile.SaveToFile(fib, filePath, true);
            }

            fib.Dispose();
        }
Ejemplo n.º 3
0
        private void SaveStitchedImage()
        {
            if (System.IO.Path.GetExtension(this.filePath) != ".ics")
            {
                MessageBox.Show("Saving in formats other than ics may result " +
                                "in a loss of infomation.", "Warning");
            }

            if (this.threadController != null)
            {
                this.threadController.ReportThreadStarted(this, "Started Image Export");
            }

            FreeImageAlgorithmsBitmap stitchedImage = this.Stitch(this.saveDialog.ExportWidth,
                                                                  this.saveDialog.ExportHeight);

            if (stitchedImage == null)
            {
                this.FileToLargeError();
                return;
            }

            try
            {
                if (System.IO.Path.GetExtension(this.filePath) != ".ics")
                {
                    if (stitchedImage.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP)
                    {
                        stitchedImage.ConvertToStandardType(true);  // PRB convert takes double the memory, only do it when necessary
                    }
                    if (this.saveInfoPanel)
                    {
                        stitchedImage.Paste(this.infoBitmap, new Point(20, 20), 256);
                    }

                    //stitchedImage.SaveToFile(this.filePath);  // uses many converts and clones in FIA
                    stitchedImage.Save(this.filePath);  // PRB use a simpler native free_image save
                }
                else
                {
                    // infoBitmap is 8bit for greyscale or 24bit colour
                    // If we are saving a greyscale image with > 8 bits
                    // we need to scale the infoBitmap to the min and max
                    // possible values of the stitchedImage.
                    if (this.saveInfoPanel)
                    {
                        if (MosaicWindow.MosaicInfo.IsGreyScale && MosaicWindow.MosaicInfo.FreeImageType != this.infoBitmap.ImageType)
                        {
                            double min, max;
                            stitchedImage.FindMinMaxIntensity(out min, out max);
                            this.infoBitmap.StretchImageToType(MosaicWindow.MosaicInfo.FreeImageType, max);
                        }

                        stitchedImage.Paste(this.infoBitmap, new Point(20, 20));
                    }

                    IcsFile.SaveToFile(stitchedImage, this.filePath, true);

                    if (MosaicWindow.MosaicInfo.MetaData != null)
                    {
                        IcsFile icsFile = new IcsFile(this.filePath);

                        // We have to add the metadata to reflect the
                        // exported image.
                        //                       if(MosaicWindow.MosaicInfo.MetaData.ContainsKey("extents"))
                        {
                            string extentString = String.Format("{0:#.###e+000} {1:#.###e+000}",
                                                                this.saveDialog.NativeRegionWidth * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel,
                                                                this.saveDialog.NativeRegionHeight * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel);

                            MosaicWindow.MosaicInfo.MetaData["extents"] = extentString;
                            MosaicWindow.MosaicInfo.MetaData["units"]   = "um um";
                        }

//                        if (MosaicWindow.MosaicInfo.MetaData.ContainsKey("image physical_sizex"))
                        {
                            string extentString = String.Format("{0:#.###e+000}",
                                                                this.saveDialog.NativeRegionWidth * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel);

                            MosaicWindow.MosaicInfo.MetaData["image physical_sizex"] = extentString;
                        }

                        //                       if (MosaicWindow.MosaicInfo.MetaData.ContainsKey("image physical_sizey"))
                        {
                            string extentString = String.Format("{0:#.###e+000}",
                                                                this.saveDialog.NativeRegionHeight * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel);

                            MosaicWindow.MosaicInfo.MetaData["image physical_sizey"] = extentString;
                        }

//                        if (MosaicWindow.MosaicInfo.MetaData.ContainsKey("image sizex"))
                        {
                            MosaicWindow.MosaicInfo.MetaData["image sizex"] = stitchedImage.Width.ToString();
                        }

//                        if (MosaicWindow.MosaicInfo.MetaData.ContainsKey("image sizey"))
                        {
                            MosaicWindow.MosaicInfo.MetaData["image sizey"] = stitchedImage.Height.ToString();
                        }

                        //                       if (MosaicWindow.MosaicInfo.MetaData.ContainsKey("dimensions"))
                        {
                            string extentString = String.Format("{0} {1}",
                                                                stitchedImage.Width,
                                                                stitchedImage.Height);

                            MosaicWindow.MosaicInfo.MetaData["dimensions"] = extentString;
                        }

                        // Add some metadata
                        MosaicWindow.MosaicInfo.MetaData["processed by"] = String.Format("{0} {1}",
                                                                                         Application.ProductName, Application.ProductVersion);

                        icsFile.AppendHistory(MosaicWindow.MosaicInfo.MetaData);

                        // calculate the um per pixel scale of the saved image
                        double xscale = this.saveDialog.NativeRegionWidth * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel / stitchedImage.Width;
                        double yscale = this.saveDialog.NativeRegionHeight * MosaicWindow.MosaicInfo.OriginalMicronsPerPixel / stitchedImage.Height;

                        icsFile.SetNativeScale(0, 0.0, xscale, "microns");
                        icsFile.SetNativeScale(1, 0.0, yscale, "microns");

                        icsFile.Close();
                    }
                }

                stitchedImage.Dispose();

                if (this.infoBitmap != null)
                {
                    this.infoBitmap.Dispose();
                }

                if (this.threadController != null)
                {
                    this.threadController.ReportThreadCompleted(this, "Exported file", false);
                }

                this.Window.TileView.AllowMouseWheelZoom = true;
                this.Window.ToolStrip.Enabled            = true;
            }
            catch (FreeImageException)
            {
                this.FileToLargeError();

                stitchedImage.Dispose();

                //          this.Export();
            }
        }