Пример #1
0
        private async void seq_save_Click(object sender, RoutedEventArgs e)
        {
            int width  = 0;
            int height = 0;

            if (!string.IsNullOrWhiteSpace(MaxWidth.Text) && MaxWidth.Text != "0")
            {
                width = Convert.ToInt32(MaxWidth.Text);
            }

            if (!string.IsNullOrWhiteSpace(MaxHeight.Text) && MaxHeight.Text != "0")
            {
                height = Convert.ToInt32(MaxHeight.Text);
            }

            var text = msg_string.Text.TrimEnd(new char[] { '\r', '\n' });

            List <string> stringsequenced = new List <string>();

            for (int i = 1; i <= text.Length; i++)
            {
                char[] container = new char[i];

                for (int x = 0; x < i; x++)
                {
                    container[x] = text[x];
                }

                stringsequenced.Add(new string(container));
            }

            await Task.Run(() =>
            {
                int counter = 1;
                foreach (var subtext in stringsequenced)
                {
                    Dispatcher.Invoke(() =>
                    {
                        msg_string.Text = subtext;

                        var res = ImageRenderer.RenderToBWImg(Encoding.UTF8.GetBytes(subtext), ((scale_options)ScaleOption.SelectedItem).value, invert_checkbox.IsChecked ?? false, width, height);

                        PngBitmapEncoder pngencoder = new PngBitmapEncoder();

                        pngencoder.Frames.Add(BitmapFrame.Create(res));

                        using (var stream = new FileStream($"Test_{counter++}.png", FileMode.Create))
                            pngencoder.Save(stream);
                    });
                }
            });
        }
Пример #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int width  = 0;
            int height = 0;

            if (!string.IsNullOrWhiteSpace(MaxWidth.Text) && MaxWidth.Text != "0")
            {
                width = Convert.ToInt32(MaxWidth.Text);
            }

            if (!string.IsNullOrWhiteSpace(MaxHeight.Text) && MaxHeight.Text != "0")
            {
                height = Convert.ToInt32(MaxHeight.Text);
            }

            //var res = ImageRenderer.RenderToBWImg(Encoding.UTF8.GetBytes(new TextRange(MessageBox.Document.ContentStart, MessageBox.Document.ContentEnd).Text));
            var text = msg_string.Text.TrimEnd(new char[] { '\r', '\n' });

            //var res = ImageRenderer.RenderToBWImg(Encoding.UTF8.GetBytes(text));
            var res = ImageRenderer.RenderToBWImg(Encoding.UTF8.GetBytes(text), ((scale_options)ScaleOption.SelectedItem).value, invert_checkbox.IsChecked ?? false, width, height);

            ShowExportDialog(res);
        }
Пример #3
0
        private static readonly Regex binaryregex = new Regex("[^0-1]+"); //regex that matches disallowed text
        private void update_preview(string string_text)
        {
            text_to_render = string_text;

            bool[] booldata = new bool[0];

            if (!binaryregex.IsMatch(text_to_render))
            {
                booldata = new bool[text_to_render.Length];

                for (int i = 0; i < text_to_render.Length; i++)
                {
                    booldata[i] = Convert.ToBoolean(char.GetNumericValue(text_to_render[i]));
                }
            }

            if (ImageView == null || imgsize == null || imgsize_scaled == null || ScaleOption == null)
            {
                return;
            }

            if (ImageView != null)
            {
                var text = text_to_render.TrimEnd(new char[] { '\r', '\n' });

                int width  = 0;
                int height = 0;

                if (!string.IsNullOrWhiteSpace(MaxWidth.Text) && MaxWidth.Text != "0")
                {
                    width = Convert.ToInt32(MaxWidth.Text);
                }

                if (!string.IsNullOrWhiteSpace(MaxHeight.Text) && MaxHeight.Text != "0")
                {
                    height = Convert.ToInt32(MaxHeight.Text);
                }

                BitmapSource result;

                string errmessage = "";

                try
                {
                    if (booldata == null || booldata.Length == 0)
                    {
                        result = ImageRenderer.RenderToBWImg(Encoding.UTF8.GetBytes(text), 1, invert_checkbox.IsChecked ?? false, width, height);
                    }
                    else
                    {
                        result = ImageRenderer.RenderToBWImg(booldata, 1, invert_checkbox.IsChecked ?? false, width, height);
                    }
                }
                catch (ImageTooSmallException)
                {
                    result     = null;
                    errmessage = "Image Too Small For Data";
                }

                if (result != null)
                {
                    ImageView.Source  = result;
                    ImageView.Stretch = Stretch.Uniform;

                    imgsize.Content         = $"Current Size : {result.PixelWidth}x{result.PixelHeight}";
                    imgsize_scaled.Content  = $"Current Scaled Size : {result.PixelWidth * ((scale_options)ScaleOption.SelectedItem).value}x{result.PixelHeight * ((scale_options)ScaleOption.SelectedItem).value}";
                    status_label.Content    = "";
                    status_label.Foreground = new SolidColorBrush(Colors.Black);
                }
                else
                {
                    ImageView.Source  = new BitmapImage(new Uri("pack://application:,,,/broken.png"));
                    ImageView.Stretch = Stretch.None;

                    imgsize.Content         = $"Current Size : NaN";
                    imgsize_scaled.Content  = $"Current Scaled Size : NaN";
                    status_label.Content    = errmessage;
                    status_label.Foreground = new SolidColorBrush(Colors.Red);
                }
            }
        }