예제 #1
0
        /// <summary>
        /// Creates a new image given the specified file format
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="inRam">if set to <c>true</c> should load entire file in ram.</param>
        /// <param name="progHandler">The prog handler.</param>
        /// <param name="bandType">Type of the band.</param>
        /// <returns></returns>
        public IImageData Create(string fileName, int width, int height, bool inRam, IProgressHandler progHandler, ImageBandType bandType)
        {
            Gdal.AllRegister();
            Driver d = GetDriverByExtension(fileName);
            if (d == null) return null;
            Dataset ds;
            if (bandType == ImageBandType.ARGB)
            {
                ds = d.Create(fileName, width, height, 4, DataType.GDT_Byte, new string[] { });
            }
            else if (bandType == ImageBandType.RGB)
            {
                ds = d.Create(fileName, width, height, 3, DataType.GDT_Byte, new string[] { });
            }
            else if (bandType == ImageBandType.PalletCoded)
            {
                ds = d.Create(fileName, width, height, 1, DataType.GDT_Byte, new string[] { });
            }
            else
            {
                ds = d.Create(fileName, width, height, 1, DataType.GDT_Byte, new string[] { });
            }

            return new GdalImage(fileName, ds, bandType);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="ds"></param>
        /// <param name="band"></param>
        internal GdalImage(string filename, Dataset ds, ImageBandType band)
        {
            _dataset = ds;
            if (band == ImageBandType.ARGB)
            {
                using (Band bnd = ds.GetRasterBand(1))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_AlphaBand);
                }
                using (Band bnd = ds.GetRasterBand(2))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_RedBand);
                }
                using (Band bnd = ds.GetRasterBand(3))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_GreenBand);
                }
                using (Band bnd = ds.GetRasterBand(4))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_BlueBand);
                }
            }
            else if (band == ImageBandType.RGB)
            {
                using (Band bnd = ds.GetRasterBand(1))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_RedBand);
                }
                using (Band bnd = ds.GetRasterBand(2))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_GreenBand);
                }
                using (Band bnd = ds.GetRasterBand(3))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_BlueBand);
                }
            }
            else if (band == ImageBandType.PalletCoded)
            {
                using (Band bnd = ds.GetRasterBand(3))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_PaletteIndex);
                }
            }
            else
            {
                using (Band bnd = ds.GetRasterBand(3))
                {
                    bnd.SetRasterColorInterpretation(ColorInterp.GCI_GrayIndex);
                }
            }

            Filename = filename;
            WorldFile = new WorldFile { Affine = new double[6] };
            Gdal.AllRegister();
        }
예제 #3
0
        /// <summary>
        /// Creates a new image given the specified file format
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="inRam">if set to <c>true</c> should load entire file in ram.</param>
        /// <param name="progHandler">The prog handler.</param>
        /// <param name="bandType">Type of the band.</param>
        /// <returns></returns>
        public IImageData Create(string fileName, int width, int height, bool inRam, IProgressHandler progHandler, ImageBandType bandType)
        {
            Driver d = GetDriverByExtension(fileName);
            if (d == null) return null;
            Dataset ds;
            switch (bandType)
            {
                case ImageBandType.ARGB:
                    ds = d.Create(fileName, width, height, 4, DataType.GDT_Byte, new string[] { });
                    break;
                case ImageBandType.RGB:
                    ds = d.Create(fileName, width, height, 3, DataType.GDT_Byte, new string[] { });
                    break;
                case ImageBandType.PalletCoded:
                    ds = d.Create(fileName, width, height, 1, DataType.GDT_Byte, new string[] { });
                    break;
                default:
                    ds = d.Create(fileName, width, height, 1, DataType.GDT_Byte, new string[] { });
                    break;
            }

            return new GdalImage(fileName, ds, bandType);
        }
예제 #4
0
        /// <summary>
        /// Creates a new image and world file, placing the default bounds at the origin, with one pixel per unit.
        /// </summary>
        /// <param name="fileName">
        /// The string fileName
        /// </param>
        /// <param name="width">
        /// The integer width
        /// </param>
        /// <param name="height">
        /// The integer height
        /// </param>
        /// <param name="bandType">The ImageBandType that clarifies how the separate bands are layered in the image.</param>
        public override IImageData Create(string fileName, int width, int height, ImageBandType bandType)
        {
            Filename = fileName;
            WorldFile = new WorldFile();
            double[] aff = new[] { 1.0, 0, 0, -1.0, 0, height };
            Bounds = new RasterBounds(height, width, aff);
            WorldFile.Filename = WorldFile.GenerateFilename(fileName);
            Width = width;
            Height = height;
            _myImage = new Bitmap(width, height);
            string ext = Path.GetExtension(fileName);
            switch (ext)
            {
                case ".bmp":
                    _myImage.Save(fileName, ImageFormat.Bmp);
                    break;
                case ".emf":
                    _myImage.Save(fileName, ImageFormat.Emf);
                    break;
                case ".exf":
                    _myImage.Save(fileName, ImageFormat.Exif);
                    break;
                case ".gif":
                    _myImage.Save(fileName, ImageFormat.Gif);
                    break;
                case ".ico":
                    _myImage.Save(fileName, ImageFormat.Icon);
                    break;
                case ".jpg":
                    _myImage.Save(fileName, ImageFormat.Jpeg);
                    break;
                case ".mbp":
                    _myImage.Save(fileName, ImageFormat.MemoryBmp);
                    break;
                case ".png":
                    _myImage.Save(fileName, ImageFormat.Png);
                    break;
                case ".tif":
                    _myImage.Save(fileName, ImageFormat.Tiff);
                    break;
                case ".wmf":
                    _myImage.Save(fileName, ImageFormat.Wmf);
                    break;
            }

            NumBands = 4;
            BytesPerPixel = 4;
            CopyBitmapToValues();

            return this;
        }
예제 #5
0
 /// <summary>
 /// Creates a new image and world file, placing the default bounds at the origin, with one pixel per unit.
 /// </summary>
 /// <param name="fileName">The string fileName</param>
 /// <param name="width">The integer width</param>
 /// <param name="height">The integer height</param>
 /// <param name="bandType">The color band type</param>
 public virtual IImageData Create(string fileName, int width, int height, ImageBandType bandType)
 {
     return DataManager.DefaultDataManager.CreateImage(fileName, height, width, bandType);
 }
예제 #6
0
 /// <summary>
 /// Creates a new instance of an Image.
 /// </summary>
 /// <param name="fileName">The string fileName to use</param>
 /// <param name="width">The integer width in pixels</param>
 /// <param name="height">The integer height in pixels</param>
 /// <param name="inRam">Boolean, true if the entire contents should be stored in memory</param>
 /// <param name="progHandler">A Progress handler to use</param>
 /// <param name="band">.Net type ignores this for now.</param>
 /// <returns>
 /// A New IImageData object allowing access to the content of the image
 /// </returns>
 public IImageData Create(string fileName, int width, int height, bool inRam, IProgressHandler progHandler, ImageBandType band)
 {
     InRamImageData img = new InRamImageData();
     img.Create(fileName, width, height, band);
     return img;
 }
예제 #7
0
        /// <summary>
        /// Creates a new filename and saves the content from the current BitmapGetter to the
        /// file format.  This relies on the DataManager and will only be successful for
        /// formats supported by the write format possibility.  This will not update this raster
        /// </summary>
        /// <param name="fileName">The string fileName to write to</param>
        /// <param name="progressHandler">The progress handler for creating a new bitmap.</param>
        /// <param name="bandType">The band type ot use.</param>
        public void ExportBitmap(string fileName, IProgressHandler progressHandler, ImageBandType bandType)
        {
            int rows = DataSet.NumRowsInFile;
            int cols = DataSet.NumColumnsInFile;

            IImageData result = DataManager.DefaultDataManager.CreateImage(fileName, rows, cols, false, progressHandler, bandType);
            int numBlocks = 1;
            if (rows * cols > 8000 * 8000)
            {
                numBlocks = Convert.ToInt32(Math.Ceiling(8000 * 8000 / (double)cols));
            }
            int blockRows = (8000 * 8000) / cols;
            ProjectionHelper ph = new ProjectionHelper(DataSet.Extent, new Rectangle(0, 0, cols, rows));
            for (int iblock = 0; iblock < numBlocks; iblock++)
            {
                int rowCount = blockRows;
                if (iblock == numBlocks - 1) rowCount = rows - blockRows * iblock;
                Rectangle r = new Rectangle(0, iblock * blockRows, cols, rowCount);
                Bitmap block = BitmapGetter.GetBitmap(ph.PixelToProj(r), r);
                result.WriteBlock(block, 0, iblock * blockRows);
            }
        }
예제 #8
0
 /// <summary>
 ///  Creates a bmp texture and saves it to the specified fileName.
 /// </summary>
 /// <param name="fileName">The string fileName to write to</param>
 /// <param name="bandType">The color band type.</param>
 public void ExportBitmap(string fileName, ImageBandType bandType)
 {
     ExportBitmap(fileName, DataSet.ProgressHandler, bandType);
 }
예제 #9
0
 /// <summary>
 /// Creates a new image using an appropriate data provider
 /// </summary>
 /// <param name="fileName">The string fileName to open an image for</param>
 /// <param name="width">The integer width in pixels</param>
 /// <param name="height">The integer height in pixels</param>
 /// <param name="bandType">The band color type</param>
 /// <returns>An IImageData interface allowing access to image data</returns>
 public virtual IImageData CreateImage(string fileName, int width, int height, ImageBandType bandType)
 {
     return(CreateImage(fileName, width, height, LoadInRam, ProgressHandler, bandType));
 }
예제 #10
0
        /// <summary>
        /// Creates a new instance of an Image.
        /// </summary>
        /// <param name="fileName">The string fileName to use</param>
        /// <param name="width">The integer width in pixels</param>
        /// <param name="height">The integer height in pixels</param>
        /// <param name="inRam">Boolean, true if the entire contents should be stored in memory</param>
        /// <param name="progHandler">A Progress handler to use</param>
        /// <param name="band">.Net type ignores this for now.</param>
        /// <returns>
        /// A New IImageData object allowing access to the content of the image
        /// </returns>
        public IImageData Create(string fileName, int width, int height, bool inRam, IProgressHandler progHandler, ImageBandType band)
        {
            InRamImageData img = new InRamImageData();

            img.Create(fileName, width, height, band);
            return(img);
        }
예제 #11
0
 /// <summary>
 ///  Creates a bmp texture and saves it to the specified fileName.
 /// </summary>
 /// <param name="fileName">The string fileName to write to</param>
 /// <param name="bandType">The color band type.</param>
 public void ExportBitmap(string fileName, ImageBandType bandType)
 {
     ExportBitmap(fileName, DataSet.ProgressHandler, bandType);
 }
예제 #12
0
        /// <summary>
        /// Creates a new image using an appropriate data provider.
        /// </summary>
        /// <param name="fileName">The string fileName to open an image for.</param>
        /// <param name="width">The integer width in pixels.</param>
        /// <param name="height">The integer height in pixels.</param>
        /// <param name="inRam">Boolean, true if the entire file should be created in memory.</param>
        /// <param name="progHandler">A Progress handler.</param>
        /// <param name="bandType">The band color type.</param>
        /// <returns>An IImageData interface allowing access to image data.</returns>
        public virtual IImageData CreateImage(string fileName, int width, int height, bool inRam, IProgressHandler progHandler, ImageBandType bandType)
        {
            // First check for the extension in the preferred plugins list
            string ext = Path.GetExtension(fileName)?.ToLower();

            if (ext != null)
            {
                IImageData result;
                if (PreferredProviders.ContainsKey(ext))
                {
                    if (PreferredProviders[ext] is IImageDataProvider rp)
                    {
                        result = rp.Create(fileName, width, height, inRam, progHandler, bandType);
                        if (result != null)
                        {
                            return(result);
                        }
                    }

                    // if we get here, we found the provider, but it did not succeed in opening the file.
                }

                // Then check the general list of developer specified providers... but not the directory providers
                foreach (IDataProvider dp in DataProviders)
                {
                    if (GetSupportedExtensions(dp.DialogWriteFilter).Contains(ext))
                    {
                        if (dp is IImageDataProvider rp)
                        {
                            // attempt to open with the fileName.
                            result = rp.Create(fileName, width, height, inRam, progHandler, bandType);
                            if (result != null)
                            {
                                return(result);
                            }
                        }
                    }
                }
            }

            throw new ApplicationException(DataStrings.FileTypeNotSupported);
        }
예제 #13
0
        /// <summary>
        /// Creates a new image given the specified file format.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="inRam">if set to <c>true</c> should load entire file in ram.</param>
        /// <param name="progHandler">The prog handler.</param>
        /// <param name="bandType">Type of the band.</param>
        /// <returns>The created image data.</returns>
        public IImageData Create(string fileName, int width, int height, bool inRam, IProgressHandler progHandler, ImageBandType bandType)
        {
            Driver d = GetDriverByExtension(fileName);

            if (d == null)
            {
                return(null);
            }

            Dataset ds;

            switch (bandType)
            {
            case ImageBandType.ARGB:
                ds = d.Create(fileName, width, height, 4, DataType.GDT_Byte, new string[] { });
                break;

            case ImageBandType.RGB:
                ds = d.Create(fileName, width, height, 3, DataType.GDT_Byte, new string[] { });
                break;

            case ImageBandType.PalletCoded:
                ds = d.Create(fileName, width, height, 1, DataType.GDT_Byte, new string[] { });
                break;

            default:
                ds = d.Create(fileName, width, height, 1, DataType.GDT_Byte, new string[] { });
                break;
            }

            return(new GdalImage(fileName, ds, bandType));
        }
예제 #14
0
 /// <summary>
 /// Creates a new image and world file, placing the default bounds at the origin, with one pixel per unit.
 /// </summary>
 /// <param name="fileName">The string fileName</param>
 /// <param name="width">The integer width</param>
 /// <param name="height">The integer height</param>
 /// <param name="bandType">The color band type</param>
 public virtual IImageData Create(string fileName, int width, int height, ImageBandType bandType)
 {
     return(DataManager.DefaultDataManager.CreateImage(fileName, height, width, bandType));
 }
예제 #15
0
        /// <summary>
        /// Creates a new image given the specified file format
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="inRam">if set to <c>true</c> should load entire file in ram.</param>
        /// <param name="progHandler">The prog handler.</param>
        /// <param name="bandType">Type of the band.</param>
        /// <returns></returns>
        public IImageData Create(string fileName, int width, int height, bool inRam, IProgressHandler progHandler, ImageBandType bandType)
        {
            Gdal.AllRegister();
            Driver d = GetDriverByExtension(fileName);

            if (d == null)
            {
                return(null);
            }
            Dataset ds;

            if (bandType == ImageBandType.ARGB)
            {
                ds = d.Create(fileName, width, height, 4, DataType.GDT_Byte, new string[] { });
            }
            else if (bandType == ImageBandType.RGB)
            {
                ds = d.Create(fileName, width, height, 3, DataType.GDT_Byte, new string[] { });
            }
            else if (bandType == ImageBandType.PalletCoded)
            {
                ds = d.Create(fileName, width, height, 1, DataType.GDT_Byte, new string[] { });
            }
            else
            {
                ds = d.Create(fileName, width, height, 1, DataType.GDT_Byte, new string[] { });
            }

            return(new GdalImage(fileName, ds, bandType));
        }
예제 #16
0
        /// <summary>
        /// Creates a new image and world file, placing the default bounds at the origin, with one pixel per unit.
        /// </summary>
        /// <param name="fileName">
        /// The string fileName
        /// </param>
        /// <param name="width">
        /// The integer width
        /// </param>
        /// <param name="height">
        /// The integer height
        /// </param>
        /// <param name="bandType">The ImageBandType that clarifies how the separate bands are layered in the image.</param>
        public override IImageData Create(string fileName, int width, int height, ImageBandType bandType)
        {
            Filename  = fileName;
            WorldFile = new WorldFile();
            double[] aff = new[] { 1.0, 0, 0, -1.0, 0, height };
            Bounds             = new RasterBounds(height, width, aff);
            WorldFile.Filename = WorldFile.GenerateFilename(fileName);
            Width    = width;
            Height   = height;
            _myImage = new Bitmap(width, height);
            string ext = Path.GetExtension(fileName);

            switch (ext)
            {
            case ".bmp":
                _myImage.Save(fileName, ImageFormat.Bmp);
                break;

            case ".emf":
                _myImage.Save(fileName, ImageFormat.Emf);
                break;

            case ".exf":
                _myImage.Save(fileName, ImageFormat.Exif);
                break;

            case ".gif":
                _myImage.Save(fileName, ImageFormat.Gif);
                break;

            case ".ico":
                _myImage.Save(fileName, ImageFormat.Icon);
                break;

            case ".jpg":
                _myImage.Save(fileName, ImageFormat.Jpeg);
                break;

            case ".mbp":
                _myImage.Save(fileName, ImageFormat.MemoryBmp);
                break;

            case ".png":
                _myImage.Save(fileName, ImageFormat.Png);
                break;

            case ".tif":
                _myImage.Save(fileName, ImageFormat.Tiff);
                break;

            case ".wmf":
                _myImage.Save(fileName, ImageFormat.Wmf);
                break;
            }

            NumBands      = 4;
            BytesPerPixel = 4;
            CopyBitmapToValues();

            return(this);
        }