Ejemplo n.º 1
0
 private Bitmap BuildBitmap(T[][] buffers, LevelDef level, TileIdentify tile)
 {
     using (IBitmapBuilder <T> builder = GetBitmapBuilder())
     {
         Bitmap bitmap = null;
         if (buffers.Length == 1)
         {
             bitmap         = new Bitmap(_tileSize, _tileSize, PixelFormat.Format8bppIndexed);
             bitmap.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette();
             if (st1 == null && _stretcher == null)
             {
                 builder.Build(tile.Width, tile.Height, tile.OffsetX, tile.OffsetY, buffers[0], ref bitmap);
             }
             else
             {
                 if (_stretcher != null)
                 {
                     builder.Build(tile.Width, tile.Height, tile.OffsetX, tile.OffsetY, buffers[0], _stretcher, ref bitmap);
                 }
                 else
                 {
                     builder.Build(tile.Width, tile.Height, tile.OffsetX, tile.OffsetY, buffers[0], st1.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;
             }
         }
         else if (buffers.Length == 3)
         {
             bitmap = new Bitmap(_tileSize, _tileSize, PixelFormat.Format24bppRgb);
             if (st1 == null || st2 == null || st3 == null)
             {
                 builder.Build(tile.Width, tile.Height, tile.OffsetX, tile.OffsetY, buffers[0], buffers[1], buffers[2], ref bitmap);
             }
             else
             {
                 builder.Build(tile.Width, tile.Height, tile.OffsetX, tile.OffsetY, buffers[0], buffers[1], buffers[2], st1.Stretcher, st2.Stretcher, st3.Stretcher, ref bitmap);
             }
         }
         return(bitmap);
     }
 }
Ejemplo n.º 2
0
        public Bitmap GetOverview(IRasterDataProvider dataProvider, int width, int height, int[] bands, Action <int> progress)
        {
            T[][]    buffers   = new T[bands.Length][];
            T[]      rowBuffer = new T[width];
            GCHandle handle    = GCHandle.Alloc(rowBuffer, GCHandleType.Pinned);

            try
            {
                IntPtr rowPtr = handle.AddrOfPinnedObject();
                int    offset = 0;
                for (int b = 0; b < bands.Length; b++, offset += height)
                {
                    buffers[b] = ReadBandBuffer(dataProvider, rowPtr, bands[b], width, height, offset, progress);
                }
                //
                using (IBitmapBuilder <T> builder = GetBitmapBuilder())
                {
                    Bitmap bitmap = null;
                    if (buffers.Length == 1)
                    {
                        bitmap         = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
                        bitmap.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette();
                        if (st1 == null)
                        {
                            builder.Build(width, height, 0, 0, buffers[0], ref bitmap);
                        }
                        else
                        {
                            builder.Build(width, height, 0, 0, buffers[0], st1.Stretcher, ref bitmap);
                        }
                    }
                    else if (buffers.Length == 3)
                    {
                        bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
                        if (st1 == null || st2 == null || st3 == null)
                        {
                            builder.Build(width, height, 0, 0, buffers[0], buffers[1], buffers[2], ref bitmap);
                        }
                        else
                        {
                            builder.Build(width, height, 0, 0, buffers[0], buffers[1], buffers[2], st1.Stretcher, st2.Stretcher, st3.Stretcher, ref bitmap);
                        }
                    }
                    return(bitmap);
                }
            }
            finally
            {
                handle.Free();
            }
        }
Ejemplo n.º 3
0
        private void BuildOneTile(TileData redData, TileData greenData, TileData blueData, int x, int y, Rectangle rasterWindowEnvelope, Graphics g)
        {
            LevelId lv      = _tileComputer.Levels[redData.Tile.LevelNo];
            int     w       = redData.Tile.Width;
            int     h       = redData.Tile.Height;
            Bitmap  tBitmap = new Bitmap(w, h, PixelFormat.Format24bppRgb);

            using (IBitmapBuilder <byte> builder = BitmapBuilderFactory.CreateBitmapBuilderByte())
            {
                builder.Build(w, h, redData.Data as byte[],
                              greenData.Data as byte[],
                              blueData.Data as byte[], ref tBitmap);
            }
            g.DrawImage(tBitmap, x, y);
            tBitmap.Dispose();
        }
Ejemplo n.º 4
0
        public static Bitmap GetBitmapUseOriginResolution(this IRasterDrawing drawing)
        {
            IOverviewGenerator gen = drawing.DataProviderCopy as IOverviewGenerator;

            if (drawing.SelectedBandNos == null)
            {
                return(null);
            }
            Bitmap bm = null;

            if (drawing.SelectedBandNos.Length == 1)
            {
                bm         = new Bitmap(drawing.DataProviderCopy.Width, drawing.DataProviderCopy.Height, PixelFormat.Format8bppIndexed);
                bm.Palette = BitmapBuilderFactory.GetDefaultGrayColorPalette();
            }
            else
            {
                try
                {
                    bm = new Bitmap(drawing.DataProviderCopy.Width, drawing.DataProviderCopy.Height, PixelFormat.Format24bppRgb);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("无法创建过大的Bitmap[{0}*{1}]", drawing.DataProviderCopy.Width, drawing.DataProviderCopy.Height), ex.InnerException);
                }
            }
            string ext = Path.GetExtension(drawing.FileName).ToLower();

            if (ext == ".bmp" || ext == ".png" || ext == ".jpg" || ext == ".jpeg")
            {
                bm = (Bitmap)Bitmap.FromFile(drawing.FileName);
            }
            else
            {
                gen.Generate(drawing.SelectedBandNos, ref bm);
            }
            IRgbProcessorStack stack = drawing.RgbProcessorStack;

            stack.Apply(null, bm);
            return(bm);
        }
Ejemplo n.º 5
0
 protected override IBitmapBuilder <double> GetBitmapBuilder()
 {
     return(BitmapBuilderFactory.CreateBitmapBuilderDouble());
 }
Ejemplo n.º 6
0
 protected override IBitmapBuilder <float> GetBitmapBuilder()
 {
     return(BitmapBuilderFactory.CreateBitmapBuilderFloat());
 }
Ejemplo n.º 7
0
 protected override IBitmapBuilder <Int64> GetBitmapBuilder()
 {
     return(BitmapBuilderFactory.CreateBitmapBuilderInt64());
 }
Ejemplo n.º 8
0
 protected override IBitmapBuilder <UInt32> GetBitmapBuilder()
 {
     return(BitmapBuilderFactory.CreateBitmapBuilderUInt32());
 }
Ejemplo n.º 9
0
 protected override IBitmapBuilder <byte> GetBitmapBuilder()
 {
     return(BitmapBuilderFactory.CreateBitmapBuilderByte());
 }