Esempio n. 1
0
        public Extras(IEndlessCanvas target, FloatingImage?importFloat, FloatingText?textFloat)
        {
            _target      = target ?? throw new ArgumentNullException(nameof(target));
            _importFloat = importFloat;
            _textFloat   = textFloat;
            InitializeComponent();

            if (exportButton != null)
            {
                exportButton.Enabled = target.SelectedTiles().Count > 0;
            }
        }
Esempio n. 2
0
        private void ExportButton_Click(object sender, EventArgs e)
        {
            if (saveJpegDialog == null)
            {
                return;
            }
            // Pick path
            string?path;
            var    result = saveJpegDialog.ShowDialog();

            switch (result)
            {
            case DialogResult.OK:
            case DialogResult.Yes:
                path = saveJpegDialog.FileName;
                break;

            default: return;
            }

            // user feedback
            if (exportButton != null)
            {
                exportButton.Enabled = false;
            }
            Text = "Export: saving to disk";
            Refresh();


            // read selected area
            var selected = _target.SelectedTiles();

            int top    = int.MaxValue;
            int left   = int.MaxValue;
            int right  = int.MinValue;
            int bottom = int.MinValue;

            foreach (var key in selected.OrEmpty())
            {
                top    = Math.Min(top, key.Y);
                left   = Math.Min(left, key.X);
                bottom = Math.Max(bottom, key.Y);
                right  = Math.Max(right, key.X);
            }

            bottom += 1; right += 1; // include the tile contents
            var width  = (right - left) * TileImage.Size;
            var height = (bottom - top) * TileImage.Size;

            // render and save bitmap
            using (var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb))
            {
                ((EndlessCanvas)_target).RenderToImage(bmp, top, left, selected);
                Application.DoEvents();
                bmp.SaveJpeg(path);
            }


            Text = "Export COMPLETE";
            Refresh();
            if (exportButton != null)
            {
                exportButton.Enabled = _target.SelectedTiles().Count > 0;
            }
        }