private void RefreshPreview(string propertyName) { if (propertyName != "Preview" && !string.IsNullOrEmpty(selectedFormat.Trim())) { DatePrinterLayer datePrinterLayer = new DatePrinterLayer(); datePrinterLayer.LoadFromViewModel(this); using (Bitmap bitmap = new Bitmap(460, 50)) { PlatformGeoCanvas canvas = new PlatformGeoCanvas(); canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.Meter); datePrinterLayer.SafeProcess(() => { datePrinterLayer.Draw(canvas, new Collection <SimpleCandidate>()); }); 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); } } }
public static DatePrinterLayer GetCurrentDatePrinterLayer(double width, double height, double centerX, double centerY) { DatePrinterLayer datePrinterLayer = new DatePrinterLayer { DrawingExceptionMode = DrawingExceptionMode.DrawException }; datePrinterLayer.LoadFromViewModel(new DateElementViewModel() { SelectedFormat = DateTime.Now.ToShortDateString(), FontSize = 12 }); datePrinterLayer.Open(); datePrinterLayer.SetPosition(width, height, centerX, centerY, PrintingUnit.Inch); return(datePrinterLayer); }