I need to collect 1 image from 9 Bitmap and save it to the hard disk, how to do it?

  • one
    For example, using ImageMagic, you can "glue" images. - Vladimir Martyanov
  • 2
    Add the size of 9 images. create a Bitmap of this size and output 9 images to it. - Stack

1 answer 1

using System.Windows.Media.Imaging; using System.Windows.Media; var files = new[] { @"c:\temp\1.jpg", @"c:\temp\2.jpg" }; var dv = new DrawingVisual(); using (var dc = dv.RenderOpen()) { double left = 0; foreach (var file in files) { var bi = new BitmapImage(new Uri(file, UriKind.Absolute)); dc.DrawImage(bi, new Rect(left, 0, bi.Width, bi.Height)); left += bi.Width; } } var rtb = new RenderTargetBitmap((int)dv.ContentBounds.Width, (int)dv.ContentBounds.Height, 96, 96, PixelFormats.Pbgra32); rtb.Render(dv); var en = new PngBitmapEncoder(); en.Frames.Add(BitmapFrame.Create(rtb)); using (var s = File.Create(@"C:\Temp\result.png")) en.Save(s);