예제 #1
0
 public void ConfigureMapView()
 {
     MapView = new WebMapView(this);
     MapRequestConfig.ConfigureMapView(MapView);
 }
예제 #2
0
 public MapPresenter(Map map, WebMapView view)
     : base(map, view)
 {
 }
        protected override Stream RenderStreamInternal(WebMapView map, out string mimeType)
        {
            Stream stream = base.RenderStreamInternal(map, out mimeType);
            if (MapView.BackgroundColor == StyleColor.Transparent
                && TransparentColorIndex.HasValue
                && ImageCodec.Clsid == FindCodec("image/gif").Clsid)
            {


                Color trans = ViewConverter.Convert(MapView.BackgroundColor);

                using (Bitmap bmpSrc = new Bitmap(stream))
                {
                    using (Bitmap bmpTrgt = new Bitmap(bmpSrc.Width, bmpSrc.Height, PixelFormat.Format8bppIndexed))
                    {
                        ColorPalette cp = bmpSrc.Palette;
                        ColorPalette ncp = bmpTrgt.Palette;

                        int n = 0;
                        foreach (Color c in cp.Entries)
                            ncp.Entries[n++] = Color.FromArgb(255, c);


                        ncp.Entries[TransparentColorIndex.Value] = Color.FromArgb(0, ncp.Entries[TransparentColorIndex.Value]);
                        bmpTrgt.Palette = ncp;


                        BitmapData src =
                            bmpSrc.LockBits(new Rectangle(0, 0, bmpSrc.Width, bmpSrc.Height),
                                            ImageLockMode.ReadOnly, bmpSrc.PixelFormat);

                        BitmapData dst =
                            bmpTrgt.LockBits(new Rectangle(0, 0, bmpTrgt.Width, bmpTrgt.Height), ImageLockMode.WriteOnly,
                                             bmpTrgt.PixelFormat);


                        unsafe
                        {


                            for (int y = 0; y < bmpSrc.Height; y++)

                                for (int x = 0; x < bmpSrc.Width; x++)
                                {

                                    ((byte*)dst.Scan0.ToPointer())[(dst.Stride * y) + x] =
                                        ((byte*)src.Scan0.ToPointer())[(src.Stride * y) + x];

                                }

                        }

                        bmpSrc.UnlockBits(src);
                        bmpTrgt.UnlockBits(dst);

                        MemoryStream ms = new MemoryStream();
                        bmpTrgt.Save(ms, ImageFormat.Gif);

                        return ms;
                    }
                }
            }


            return stream;
        }