private void TextElementEntity_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (withPreview && e.PropertyName != "Preview" && !string.IsNullOrEmpty(text.Trim()))
            {
                LabelPrinterLayer labelPrinterLayer = new LabelPrinterLayer();
                labelPrinterLayer.LoadFromViewModel(this);
                using (Bitmap bitmap = new Bitmap(250, 100))
                {
                    PlatformGeoCanvas canvas = new PlatformGeoCanvas();
                    canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.Meter);

                    labelPrinterLayer.SafeProcess(() =>
                    {
                        labelPrinterLayer.Draw(canvas, new Collection <SimpleCandidate>());
                    });

                    //labelPrinterLayer.Open();
                    //labelPrinterLayer.Draw(canvas, new System.Collections.ObjectModel.Collection<SimpleCandidate>());
                    //labelPrinterLayer.Close();
                    canvas.EndDrawing();
                    MemoryStream ms = new MemoryStream();
                    bitmap.Save(ms, ImageFormat.Png);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = ms;
                    bitmapImage.EndInit();
                    preview = bitmapImage;
                    RaisePropertyChanged(() => Preview);
                }
            }
        }
Exemple #2
0
        public static LabelPrinterLayer GetLabelPrinterLayer(string text, double width, double height, double centerX, double centerY)
        {
            LabelPrinterLayer labelPrinterLayer = new LabelPrinterLayer {
                DrawingExceptionMode = DrawingExceptionMode.DrawException
            };

            labelPrinterLayer.LoadFromViewModel(new TextElementViewModel(false)
            {
                Text = text, FontSize = 34
            });
            labelPrinterLayer.Open();
            labelPrinterLayer.SetPosition(width, height, centerX, centerY, PrintingUnit.Inch);
            return(labelPrinterLayer);
        }