Exemple #1
0
        public async static Task <byte[][]> hdt(MCTransferAsync data, int worldX, int worldZ)
        {
            var w = new WorldVoxelEx()
            {
                R = 1, X = worldX, Z = worldZ
            };

            byte[][] map = new byte[2][];

            var hd = new byte[512 * 512];

            var hdt = $"r.{w.Xs}.{w.Zs}.hdt";

            using (var mem = new MemoryStream())
            {
                if (await data.TransferNext(hdt, mem, TxRx.RECEIVE))
                {
                    mem.Position = 0;

                    mem.Read(hd, 0, 512 * 512);
                    map[0] = hd;

                    hd = new byte[512 * 512];
                    mem.Read(hd, 0, 512 * 512);
                    map[1] = hd;
                }
                else
                {
                    map[0] = new byte[512 * 512];
                    map[1] = new byte[512 * 512];
                }
            }

            return(map);
        }
Exemple #2
0
        public static async Task StitchAsync(WorldVoxelEx wv, string ImgPath, MCTransferAsync Tiles, MCTransferAsync Maps, int Regions = 2, bool TransferBack = true)
        {
            var map = wv.CopyToWorld(Regions);

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

                            var b = await GetImgAsync(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 = await GetImgAsync(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;

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

                            b.Dispose();
                            g.Dispose();
                        }
                }
                catch (Exception ex)
                {
                }
            }

            await Task.WhenAll(MakeImage("tile"), MakeImage("topo"));
        }
Exemple #3
0
        public static async Task <Bitmap> GetImgAsync(MemoryStream ms, MCTransferAsync 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 == await 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);
        }