public byte[] ProcessImages(List<byte[]> images, Size liveViewImageStreamSize, Template pattern) { var defWidth = liveViewImageStreamSize.Width; var defHeight = liveViewImageStreamSize.Height; var hasBackground = pattern.Background != null; var hasOverlay = pattern.Overlay != null; var backgroundStream = hasBackground ? new MemoryStream(pattern.Background.Data) : null; var overlayStream = hasOverlay ? new MemoryStream(pattern.Overlay.Data) : null; var backgroundImage = backgroundStream.Return(Image.FromStream, null); var overlayImage = overlayStream.Return(Image.FromStream, null); var width = Math.Max(backgroundImage.Return(x => x.Width, 0), overlayImage.Return(x => x.Width, 0)); var height = Math.Max(backgroundImage.Return(x => x.Height, 0), overlayImage.Return(x => x.Height, 0)); if (width == 0 && height == 0) { width = defWidth; height = defHeight; } using (var backgroundBitmap = new Bitmap(width, height)) { using (var canvas = Graphics.FromImage(backgroundBitmap)) { canvas.InterpolationMode = InterpolationMode.HighQualityBicubic; // ReSharper disable once AccessToDisposedClosure backgroundImage.Do(x => canvas.DrawImage(x, new Rectangle(0, 0, width, height), new Rectangle(0, 0, x.Width, x.Height), GraphicsUnit.Pixel)); var templates = pattern.Images.ToList(); for (var i = 0; i < images.Count; i++) { var template = templates[i]; var destWidth = (int)Math.Round(width * template.Width); var destHeight = (int)Math.Round(height * template.Height); var stepX = (int)Math.Round(width * template.X); var stepY = (int)Math.Round(height * template.Y); FillCanvas(canvas, images[i], new Point(stepX, stepY), destWidth, destHeight, 0, 0); } // ReSharper disable once AccessToDisposedClosure overlayImage.Do(x => canvas.DrawImage(x, new Rectangle(0, 0, width, height), new Rectangle(0, 0, x.Width, x.Height), GraphicsUnit.Pixel)); canvas.Save(); } return backgroundBitmap.ToBytes(); } }
public CompositionModelProcessor Create(Template composition) { return new CompositionModelProcessor(composition, _imageProcessor,_imageUtils); }
public CompositionProcessingResult(Template pattern, byte[] result) { SelectedComposition = pattern; ImageResult = result; }
private TemplateViewModel FromTemplate(Template template) { var background = template.Background.With(FromImage); return new TemplateViewModel(template.Name, (uint)template.Width, (uint)template.Height, template.Id, template.Images.Select(c => new TemplateImageViewModel(c.X, c.Y, c.Width, c.Height, c.Id, background.Width, background.Height,template.IsInstaPrinterTemplate)), background, template.Overlay.With(FromImage), template.IsInstaPrinterTemplate); }
private IEnumerable<TemplateImageData> FromTemplate(Template template) { return template.Images.Select(c => new TemplateImageData() { X = c.X, Y = c.Y, Width = c.Width, Height = c.Height}); }