private ImageSource CreateImage(CustomMaterial material) { var bitmapSourceBackground = material.FlyerFrontSide.ToBitmapImage(); var visual = new DrawingVisual(); using (var drawingContext = visual.RenderOpen()) { drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, bitmapSourceBackground.Width, bitmapSourceBackground.Height))); drawingContext.DrawImage(bitmapSourceBackground, new Rect(0, 0, bitmapSourceBackground.Width, bitmapSourceBackground.Height)); foreach (var textField in material.MaterialFields.Select(materialToTextFieldConverter.CreateTextField)) { drawingContext.DrawText(textField.FormattedText, textField.Origin); } if (material.CustomLogo.HasLogo) { var flyerLogo = material.CustomLogo.Logo.ToBitmapImage(); drawingContext.DrawImage(flyerLogo, new Rect(material.CustomLogo.LogoLeftMargin, material.CustomLogo.LogoTopMargin, material.CustomLogo.LogoWidth, material.CustomLogo.LogoHeight)); } } var image = new DrawingImage(visual.Drawing); image.Freeze(); return image; }
public MemoryStream CreateFlyer(CustomMaterial material) { var image = CreateImage(material); return SaveDrawingImage(image); }