Exemplo n.º 1
0
 private void btnGetVisibleTiles_Click(object sender, EventArgs e)
 {
     Console.WriteLine("////////////");
     Console.WriteLine("///Visible Tiles:");
     TileData[][] tiles = _tileMemeoryCacheManager.GetVisibleTileDatas();
     for (int b = 0; b < tiles.Length; b++)
     {
         TileData[] bandTiles = tiles[b];
         Console.WriteLine("/// Band " + b.ToString());
         foreach (TileData t in bandTiles)
         {
             Console.WriteLine("     " + t.Tile.ToString());
             using (IBitmapBuilder <byte> builder = BitmapBuilderFactory.CreateBitmapBuilderByte())
             {
                 Bitmap bm = new Bitmap(t.Tile.Width, t.Tile.Height, PixelFormat.Format8bppIndexed);
                 bm.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette();
                 builder.Build(t.Tile.Width, t.Tile.Height, t.Data as Byte[], ref bm);
                 bm.Save("d:\\B" + t.BandNo.ToString() + "_L" + t.Tile.LevelNo.ToString() + "_R" +
                         t.Tile.Row.ToString() + "_C" + t.Tile.Col.ToString() + ".bmp", ImageFormat.Bmp);
             }
         }
     }
     //
     BuildBitmap(tiles);
 }
Exemplo n.º 2
0
        public static Bitmap ToBitmap <T>(T[] buffer, int width, int height, string colorTableName)
        {
            //string colorTableName = string.Format("Cloudsat.{0}", "2B-GEOPROF.Radar_Reflectivity");
            ProductColorTable productColorTable = ProductColorTableFactory.GetColorTable(colorTableName);

            if (productColorTable == null)
            {
                return(null);
            }
            RgbStretcherProvider stretcherProvier = new RgbStretcherProvider();
            ColorMapTable <int>  colorMapTable    = null;
            Func <T, byte>       stretcher        = null;
            IBitmapBuilder <T>   builder          = null;
            TypeCode             t = Type.GetTypeCode(default(T).GetType());

            if (t == TypeCode.Single)
            {
                stretcher = stretcherProvier.GetStretcher(enumDataType.Float, productColorTable, out colorMapTable) as Func <T, byte>;
                builder   = BitmapBuilderFactory.CreateBitmapBuilderFloat() as IBitmapBuilder <T>;
            }
            else if (t == TypeCode.Int16)
            {
                stretcher = stretcherProvier.GetStretcher(enumDataType.Int16, productColorTable, out colorMapTable) as Func <T, byte>;
                builder   = BitmapBuilderFactory.CreateBitmapBuilderInt16() as IBitmapBuilder <T>;
            }
            Bitmap bitmap = null;

            bitmap         = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
            bitmap.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette();
            try
            {
                builder.Build(width, height, buffer, stretcher, ref bitmap);
                if (colorMapTable != null)
                {
                    ColorPalette plt = BitmapBuilderFactory.GetDefaultGrayColorPalette();
                    for (int i = 0; i < 256; i++)
                    {
                        plt.Entries[i] = Color.Black;
                    }
                    int idx = 1;
                    foreach (ColorMapItem <int> item in colorMapTable.Items)
                    {
                        for (int v = item.MinValue; v < item.MaxValue; v++)
                        {
                            plt.Entries[idx] = item.Color;
                        }
                        idx++;
                    }
                    bitmap.Palette = plt;
                }
                return(bitmap);
            }
            finally
            {
            }
        }
Exemplo n.º 3
0
        private void UpdateBuffer()
        {
            ICanvasViewer viewer = _session.SmartWindowManager.ActiveCanvasViewer;

            if (viewer == null || viewer.ActiveObject == null)
            {
                return;
            }
            IRasterDrawing drawing = viewer.ActiveObject as IRasterDrawing;

            if (drawing == null || drawing.DataProvider == null)
            {
                return;
            }
            using (IRasterDataProvider prd = GeoDataDriver.Open(drawing.FileName) as IRasterDataProvider)
            {
                IOverviewGenerator ov = prd as IOverviewGenerator;
                if (ov == null)
                {
                    return;
                }
                Size size = ov.ComputeSize(200);
                if (_buffer != null)
                {
                    _buffer.Dispose();
                }
                _defaultBands = GetDefaultBands(prd);
                if (_defaultBands == null || _defaultBands.Length == 0)
                {
                    return;
                }
                if (_defaultBands.Length == 3)
                {
                    _buffer = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb);
                }
                else if (_defaultBands.Length == 1)
                {
                    _buffer         = new Bitmap(size.Width, size.Height, PixelFormat.Format8bppIndexed);
                    _buffer.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette();
                }
                else
                {
                    return;
                }
                //
                ov.Generate(_defaultBands, ref _buffer);
                //
                _resX = drawing.OriginalEnvelope.Width / _buffer.Width;
                _resY = drawing.OriginalEnvelope.Height / _buffer.Height;
            }
        }
Exemplo n.º 4
0
        private void AVILayer_Click(object sender, EventArgs e)
        {
            string[] fnames = null;
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter      = "栅格文件(*.dat)|*.dat";
                dlg.Multiselect = true;
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    fnames = dlg.FileNames;
                }
                else
                {
                    return;
                }
            }
            IRasterDataProvider prd;
            List <Bitmap>       bmps = new List <Bitmap>();
            Bitmap bp;

            foreach (string fname in fnames)
            {
                using (prd = GeoDataDriver.Open(fname) as IRasterDataProvider)
                {
                    IOverviewGenerator ovg = prd as IOverviewGenerator;
                    Size size = ovg.ComputeSize(800);
                    bp         = new Bitmap(size.Width, size.Height, PixelFormat.Format8bppIndexed);
                    bp.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette();
                    ovg.Generate(new int[] { 1 }, ref bp);
                    if (bp != null)
                    {
                        bmps.Add(bp);
                    }
                }
            }
            if (bmps.Count == 0)
            {
                return;
            }
            //IAVILayer aviLyr = new AVILayer(bmps.ToArray(), new GeoDo.RSS.Core.DrawEngine.CoordEnvelope(112, 113, 39, 40), 500);
            //aviLyr.IsRunning = true;
            //_canvas.LayerContainer.Layers.Add(aviLyr);
            ////_canvas.PrimaryDrawObject = drawings[0];
            ////_canvas.CurrentEnvelope = drawings[0].OriginalEnvelope;
            ////for (int i = 0; i < drawings.Length; i++)
            ////    drawings[i].StartLoading((t, p) => { Text = p.ToString() + "/" + t.ToString(); });
            //_canvas.Refresh(enumRefreshType.All);
        }