Exemplo n.º 1
0
        private Bitmap GetImg(MCTransfer transfer, string ImgPath, string filename, Size Scale)
        {
            Bitmap fb;
            Bitmap b;

            var localFileName = Path.Combine(ImgPath, filename);

            if (File.Exists(localFileName))
            {
                fb = new Bitmap(localFileName);
                b  = new Bitmap(fb, Scale);
                fb.Dispose();
                return(b);
            }

            using (MemoryStream ms = new MemoryStream())
            {
                if (true == transfer.TransferNext(filename, ms, TxRx.RECEIVE))
                {
                    fb = new Bitmap(ms);
                    b  = new Bitmap(fb, Scale);
                    fb.Dispose();
                }
                else
                {
                    b = new Bitmap(Scale.Width, Scale.Height);
                }
            }
            return(b);
        }
Exemplo n.º 2
0
        public static void Stitch(WorldVoxelEx wv, string ImgPath, MCTransfer Tiles, MCTransfer Maps, int Regions = 2, bool TransferBack = true)
        {
            var map = wv.CopyToWorld(Regions);

            using (var ms1 = new MemoryStream())
                using (var ms2 = new MemoryStream())
                {
                    void MakeImage(string ImgType)
                    {
                        var FileName      = $"{ImgType}{map.BaseFilename()}.png";
                        var LocalFileName = Path.Combine(ImgPath, FileName);

                        var b = GetImg(ms1, Maps, ImgPath, FileName, new Size(512, 512));
                        var g = Graphics.FromImage(b);

                        var img = wv.CopyToWorld(Regions);
                        var pix = WorldVoxelEx.PixelSize(img.R, wv.R);

                        var p = GetImg(ms2, (wv.R == 1) ? Tiles : Maps, ImgPath, $"{ImgType}{wv.BaseFilename()}.png", new Size(pix, pix));

                        g.DrawImage(p, img.Xo, img.Zo, pix, pix);
                        p.Dispose();

                        b.Save(LocalFileName);

                        if (TransferBack == true)
                        {
                            using (var mem = new MemoryStream())
                            {
                                b.Save(mem, System.Drawing.Imaging.ImageFormat.Png);
                                mem.Position = 0;

                                Maps.TransferNext(FileName, mem, TxRx.SEND);
                            }
                        }

                        b.Dispose();
                        g.Dispose();
                    }

                    MakeImage("tile");
                    MakeImage("topo");
                }
        }
Exemplo n.º 3
0
        public void Stitch(string ImgPath, MCTransfer Tiles, MCTransfer Maps, int Regions = 2, bool TransferBack = true)
        {
            var map = SourceList[0].CopyToWorld(Regions);

            void MakeImage(string ImgType)
            {
                var FileName      = $"{ImgType}{map.BaseFilename()}.png";
                var LocalFileName = Path.Combine(ImgPath, FileName);

                var b = GetImg(Maps, ImgPath, FileName, new Size(512, 512));
                var g = Graphics.FromImage(b);

                foreach (var src in SourceList)
                {
                    map = src.CopyToWorld(Regions);

                    var p = GetImg((src.R == 1) ? Tiles : Maps, ImgPath, $"{ImgType}{src.BaseFilename()}.png", new Size(256, 256));

                    g.DrawImage(p, map.Xo, map.Zo, 256, 256);
                    p.Dispose();
                }

                b.Save(LocalFileName);

                if (TransferBack == true)
                {
                    using (var mem = new MemoryStream())
                    {
                        b.Save(mem, System.Drawing.Imaging.ImageFormat.Png);
                        mem.Position = 0;

                        Maps.TransferNext(FileName, mem, TxRx.SEND);
                    }
                }


                b.Dispose();
                g.Dispose();
            }

            MakeImage("tile");
            MakeImage("topo");
        }
Exemplo n.º 4
0
        public static Bitmap GetImg(MemoryStream ms, MCTransfer transfer, string ImgPath, string filename, Size Scale)
        {
            Bitmap fb;
            Bitmap b;

            var localFileName = Path.Combine(ImgPath, filename);

            if (File.Exists(localFileName))
            {
                using (var fs = File.Open(localFileName, FileMode.Open))
                {
                    fs.CopyTo(ms);
                    ms.Position = 0;
                }


                fb = new Bitmap(ms);
                b  = new Bitmap(fb, Scale);
                fb.Dispose();
                return(b);
            }


            if (true == transfer.TransferNext(filename, ms, TxRx.RECEIVE))
            {
                fb = new Bitmap(ms);
                b  = new Bitmap(fb, Scale);

                fb.Dispose();
            }
            else
            {
                b = new Bitmap(Scale.Width, Scale.Height);
            }

            return(b);
        }