private void GeneratePrintFilesModel() { var paperCount = GlobalVariables.CalcPaperCount(); for (int i = 0; i < paperCount; i++) { var paper = new A4_Paper(); paper.GeneratePaper(localPrintList); paperList.Add(paper); } }
private string JoinBitmaps(A4_Paper paper) { //var fileName = GenerateFileName(paper.Cards); var fullPathfile = GlobalVariables.tempFolderPrint + paper.PaperName; var result = new Bitmap(3522, 2376); List <string> imgNames = new List <string>(4); List <Bitmap> bitmapList = new List <Bitmap>(4); for (int i = 0; i < 4; i++) { if (paper.Cards[i] == null) { break; } imgNames.Add(paper.Cards[i].Image); } foreach (var imgName in imgNames) { bitmapList.Add(BitmapImage2Bitmap(new Uri("Assets/" + imgName, UriKind.Relative))); } int Height = bitmapList.First().Height; int Width = bitmapList.First().Width; if (File.Exists(fullPathfile)) { return(fullPathfile); } using (Graphics g = Graphics.FromImage(result)) { int count = 0; foreach (var bitmap in bitmapList) { if (count == 0) { g.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height), new Rectangle(cutSize, cutSize, bitmap.Width - 2 * cutSize, bitmap.Height - 2 * cutSize), GraphicsUnit.Pixel); count++; continue; } if (count == 1) { g.DrawImage(bitmap, new Rectangle(Width, 0, Width, Height), new Rectangle(cutSize, cutSize, bitmap.Width - 2 * cutSize, bitmap.Height - 2 * cutSize), GraphicsUnit.Pixel); count++; continue; } if (count == 2) { g.DrawImage(bitmap, new Rectangle(0, Height, Width, Height), new Rectangle(cutSize, cutSize, Width - 2 * cutSize, Height - 2 * cutSize), GraphicsUnit.Pixel); count++; continue; } if (count == 3) { g.DrawImage(bitmap, new Rectangle(Width, Height, Width, Height), new Rectangle(cutSize, cutSize, Width - 2 * cutSize, Height - 2 * cutSize), GraphicsUnit.Pixel); count++; continue; } } result.Save(fullPathfile, ImageFormat.Png); g.Flush(); g.Dispose(); result.Dispose(); }; return(fullPathfile); }
private void GenerateXml(A4_Paper paper) { Grid outerGrid = new Grid(); Grid innerGrid = new Grid(); Rectangle rectangle = new Rectangle(); //Border border = new Border(); //Image image = new Image(); Button buttonPrint = new Button(); Button buttonFolder = new Button(); outerGrid.Width = 400; rectangle.Height = 200; rectangle.VerticalAlignment = VerticalAlignment.Top; rectangle.Margin = new Thickness(10, 10, 10, 10); rectangle.RadiusX = 10; rectangle.RadiusY = 10; rectangle.Fill = new SolidColorBrush(Color.FromRgb(255, 255, 255)); DropShadowEffect effect = new DropShadowEffect(); effect.BlurRadius = 15; effect.Direction = 0; effect.RenderingBias = RenderingBias.Performance; effect.ShadowDepth = 1; effect.Color = Color.FromRgb(187, 187, 187); rectangle.Effect = effect; #region //border.Width = 210; //border.Height = 150; //border.BorderThickness = new Thickness(1, 1, 1, 1); //border.BorderBrush = new SolidColorBrush(Color.FromRgb(0, 0, 0)); //border.VerticalAlignment = VerticalAlignment.Top; //border.Margin = new Thickness(0, 30, 0, 0); //var bitmap = new BitmapImage(new Uri(filePath)); //image.Source = bitmap; //image.Width = 200; //image.Height = 150; //image.VerticalAlignment = VerticalAlignment.Top; #endregion ColumnDefinition gridCol1 = new ColumnDefinition(); ColumnDefinition gridCol2 = new ColumnDefinition(); RowDefinition gridRow1 = new RowDefinition(); RowDefinition gridRow2 = new RowDefinition(); innerGrid.RowDefinitions.Add(gridRow1); innerGrid.RowDefinitions.Add(gridRow2); innerGrid.ColumnDefinitions.Add(gridCol1); innerGrid.ColumnDefinitions.Add(gridCol2); innerGrid.Width = 200; innerGrid.Height = 150; innerGrid.VerticalAlignment = VerticalAlignment.Top; innerGrid.Margin = new Thickness(0, 30, 0, 0);; for (int i = 0; i < paper.Cards.Length; i++) { int row = 0; int column = 0; switch (i) { case 0: row = 0; column = 0; break; case 1: row = 0; column = 1; break; case 2: row = 1; column = 0; break; case 3: row = 1; column = 1; break; } var grid = AddCardToInnerGrid(paper.Cards[i]); innerGrid.Children.Add(grid); Grid.SetColumn(grid, column); Grid.SetRow(grid, row); } buttonPrint.Style = Resources["PrintButtonStyle"] as Style; var icon = new PackIcon { Kind = PackIconKind.Printer }; icon.Width = 30; icon.Height = 30; icon.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); buttonPrint.Content = icon; //button.Name = "name"; buttonPrint.Click += (sender, routeEventArgs) => { var btn = sender as Button; btn.Style = Resources["PrintButtonStyleDone"] as Style; var btnIcon = new PackIcon { Kind = PackIconKind.Done }; btnIcon.Width = 0; btnIcon.Height = 0; btnIcon.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); buttonPrint.Content = btnIcon; DoubleAnimation iconWidthAnimation = new DoubleAnimation(); iconWidthAnimation.From = 0; iconWidthAnimation.To = 30; iconWidthAnimation.Duration = TimeSpan.FromMilliseconds(100); DoubleAnimation iconHeightAnimation = new DoubleAnimation(0, 30, TimeSpan.FromMilliseconds(100)); iconHeightAnimation.Completed += delegate(Object c, EventArgs d) { Process objProcess = new Process(); objProcess.StartInfo.FileName = "explorer"; objProcess.StartInfo.Arguments = GlobalVariables.tempFolderPrint + paper.PaperName; objProcess.Start(); }; btnIcon.BeginAnimation(Image.WidthProperty, iconWidthAnimation); btnIcon.BeginAnimation(Image.HeightProperty, iconHeightAnimation); }; buttonFolder.Style = Resources["OpenImageButtonStyle"] as Style; var icon_buttonFolder = new PackIcon { Kind = PackIconKind.FolderImage }; icon_buttonFolder.Width = 25; icon_buttonFolder.Height = 25; icon_buttonFolder.Foreground = new SolidColorBrush(Color.FromRgb(136, 136, 136)); buttonFolder.Content = icon_buttonFolder; //button.Name = "name"; buttonFolder.Click += (a, b) => { Process objProcess = new Process(); objProcess.StartInfo.FileName = "explorer"; objProcess.StartInfo.Arguments = GlobalVariables.tempFolderPrint; objProcess.Start(); }; StackPanel topMarginPanel = new StackPanel(); topMarginPanel.Height = 10; StackPanel buttomMarginPanel = new StackPanel(); buttomMarginPanel.Height = 30; outerGrid.Children.Add(rectangle); //border.Child = image; //outerGrid.Children.Add(border); outerGrid.Children.Add(buttonPrint); outerGrid.Children.Add(buttonFolder); outerGrid.Children.Add(innerGrid); PrintListContainer.Children.Add(topMarginPanel); PrintListContainer.Children.Add(outerGrid); PrintListContainer.Children.Add(buttomMarginPanel); }